/* * netsniff-ng - the packet sniffing beast * Copyright 2012 Daniel Borkmann. * Subject to the GPL, version 2. * Parts derived from iw, subject to ISC license. * Copyright 2007, 2008 Johannes Berg * Copyright 2007 Andy Lutomirski * Copyright 2007 Mike Kershaw * Copyright 2008-2009 Luis R. Rodriguez */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include "str.h" #include "dev.h" #include "mac80211.h" #include "xmalloc.h" #include "built_in.h" struct nl80211_state { struct nl_sock *nl_sock; struct nl_cache *nl_cache; struct genl_family *nl80211; }; static void get_mac80211_phydev(const char *device, char *phydev_path, size_t phydev_len) { int ret; char *pathstr; ssize_t num; ret = asprintf(&pathstr, "/sys/class/net/%s/phy80211", device); if (ret < 0) panic("Can't generate path name string for /sys/class/net device"); num = readlink(pathstr, phydev_path, phydev_len); if (num < 0) { if (errno == ENOENT || errno == EINVAL) panic("It's probably not a mac80211 device!\n"); panic("Can't readlink %s: %s!\n", pathstr, strerror(errno)); } xfree(pathstr); phydev_path[min_t(size_t, num, phydev_len - 1)] = 0; } static inline struct nl_msg *nl80211_nlmsg_xalloc(void) { struct nl_msg *ret = nlmsg_alloc(); if (!ret) panic("Cannot allocate nlmsg memory!\n"); return ret; } static inline struct nl_sock *nl80211_nl_socket_xalloc(void) { struct nl_sock *ret = nl_socket_alloc(); if (!ret) panic("Cannot allocate nl socket memory!\n"); return ret; } static void nl80211_init(struct nl80211_state *state) { int ret; state->nl_sock = nl80211_nl_socket_xalloc(); ret = genl_connect(state->nl_sock); if (ret) panic("Cannot connect generic netlink!\n"); ret = genl_ctrl_alloc_cache(state->nl_sock, &state->nl_cache); if (ret < 0) panic("Failed to allocate generic netlink cache: %s!", nl_geterror(-ret)); state->nl80211 = genl_ctrl_search_by_name(state->nl_cache, "nl80211"); if (!state->nl80211) panic("nl80211 not found in netlink cache!\n"); } static void nl80211_cleanup(struct nl80211_state *state) { genl_family_put(state->nl80211); nl_cache_free(state->nl_cache); nl_socket_free(state->nl_sock); } static int nl80211_wait_handler(struct nl_msg *msg __maybe_unused, void *arg) { int *finished = arg; *finished = 1; return NL_STOP; } static int nl80211_error_handler(struct sockaddr_nl *nla __maybe_unused, struct nlmsgerr *err, void *arg __maybe_unused) { panic("nl80211 returned with error (%d): %s\n", err->error, nl_geterror(err->error)); } static int nl80211_add_mon_if(struct nl80211_state *state, const char *device, const char *mondevice) { int ifindex, ret; struct nl_msg *msg; struct nl_cb *cb = NULL; int finished = 0; ifindex = device_ifindex(device); msg = nl80211_nlmsg_xalloc(); genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0, 0, NL80211_CMD_NEW_INTERFACE, 0); NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, mondevice); NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR); ret = nl_send_auto_complete(state->nl_sock, msg); if (ret < 0) { if (ret == -ENFILE) { nlmsg_free(msg); return -EBUSY; } panic("Cannot send_auto_complete!\n"); } cb = nl_cb_alloc(NL_CB_CUSTOM); if (!cb) panic("Cannot alloc nl_cb!\n"); nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, nl80211_wait_handler, &finished); nl_cb_err(cb, NL_CB_CUSTOM, nl80211_error_handler, NULL); nl_recvmsgs(state->nl_sock, cb); if (!finished) { ret = nl_wait_for_ack(state->nl_sock); if (ret < 0) { if (ret == -ENFILE) { nlmsg_free(msg); return -EBUSY; } panic("Waiting for netlink ack failed!\n"); } } nl_cb_put(cb); nlmsg_free(msg); return 0; nla_put_failure: panic("nla put failure!\n"); return -EIO; /* dummy */ } static int nl80211_del_mon_if(struct nl80211_state *state, const char *mondevice) { int ifindex, ret; struct nl_msg *msg; ifindex = device_ifindex(mondevice); msg = nl80211_nlmsg_xalloc(); genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0, 0, NL80211_CMD_DEL_INTERFACE, 0); NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); ret = nl_send_auto_complete(state->nl_sock, msg); if (ret < 0) panic("Cannot send_auto_complete!\n"); ret = nl_wait_for_ack(state->nl_sock); if (ret < 0) panic("Waiting for netlink ack failed!\n"); nlmsg_free(msg); return 0; nla_put_failure: panic("nla put failure!\n"); return -EIO; /* dummy */ } void enter_rfmon_mac80211(const char *device, char **mondev) { int ret; short flags; uint32_t n; char phydev_path[256]; struct nl80211_state nlstate; /* XXX: is this already a monN device? */ get_mac80211_phydev(device, phydev_path, sizeof(phydev_path)); nl80211_init(&nlstate); for (n = 0; n < UINT_MAX; n++) { char mondevice[32]; slprintf(mondevice, sizeof(mondevice), "mon%u", n); if (__device_ifindex(mondevice) > 0) continue; ret = nl80211_add_mon_if(&nlstate, device, mondevice); if (ret == 0) { *mondev = xstrdup(mondevice); flags = device_get_flags(*mondev); flags |= IFF_UP | IFF_RUNNING; device_set_flags(*mondev, flags); nl80211_cleanup(&nlstate); return; } } panic("No free monN interfaces!\n"); } void leave_rfmon_mac80211(const char *mondev) { short flags; struct nl80211_state nlstate; flags = device_get_flags(mondev); flags &= ~(IFF_UP | IFF_RUNNING); device_set_flags(mondev, flags); nl80211_init(&nlstate); nl80211_del_mon_if(&nlstate, mondev); nl80211_cleanup(&nlstate); } -remove&id=39cb2c9a316e77f6dfba96c543e55b6672d5a37e'>98fe974ee4e20121253de7f61fc8d01bdb3821c1 /sound/soc/codecs/cs42l42.h parent2c5d9555d6d937966d79d4c6529a5f7b9206e405 (diff)
drm/i915: Check for NULL i915_vma in intel_unpin_fb_obj()
I've seen this trigger twice now, where the i915_gem_object_to_ggtt() call in intel_unpin_fb_obj() returns NULL, resulting in an oops immediately afterwards as the (inlined) call to i915_vma_unpin_fence() tries to dereference it. It seems to be some race condition where the object is going away at shutdown time, since both times happened when shutting down the X server. The call chains were different: - VT ioctl(KDSETMODE, KD_TEXT): intel_cleanup_plane_fb+0x5b/0xa0 [i915] drm_atomic_helper_cleanup_planes+0x6f/0x90 [drm_kms_helper] intel_atomic_commit_tail+0x749/0xfe0 [i915] intel_atomic_commit+0x3cb/0x4f0 [i915] drm_atomic_commit+0x4b/0x50 [drm] restore_fbdev_mode+0x14c/0x2a0 [drm_kms_helper] drm_fb_helper_restore_fbdev_mode_unlocked+0x34/0x80 [drm_kms_helper] drm_fb_helper_set_par+0x2d/0x60 [drm_kms_helper] intel_fbdev_set_par+0x18/0x70 [i915] fb_set_var+0x236/0x460 fbcon_blank+0x30f/0x350 do_unblank_screen+0xd2/0x1a0 vt_ioctl+0x507/0x12a0 tty_ioctl+0x355/0xc30 do_vfs_ioctl+0xa3/0x5e0 SyS_ioctl+0x79/0x90 entry_SYSCALL_64_fastpath+0x13/0x94 - i915 unpin_work workqueue: intel_unpin_work_fn+0x58/0x140 [i915] process_one_work+0x1f1/0x480 worker_thread+0x48/0x4d0 kthread+0x101/0x140 and this patch purely papers over the issue by adding a NULL pointer check and a WARN_ON_ONCE() to avoid the oops that would then generally make the machine unresponsive. Other callers of i915_gem_object_to_ggtt() seem to also check for the returned pointer being NULL and warn about it, so this clearly has happened before in other places. [ Reported it originally to the i915 developers on Jan 8, applying the ugly workaround on my own now after triggering the problem for the second time with no feedback. This is likely to be the same bug reported as https://bugs.freedesktop.org/show_bug.cgi?id=98829 https://bugs.freedesktop.org/show_bug.cgi?id=99134 which has a patch for the underlying problem, but it hasn't gotten to me, so I'm applying the workaround. ] Cc: Daniel Vetter <daniel.vetter@intel.com> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Imre Deak <imre.deak@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'sound/soc/codecs/cs42l42.h')