From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
Andrei Otcheretianski <andrei.otcheretianski@intel.com>,
Johannes Berg <johannes.berg@intel.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [ 04/12] genetlink: fix family dump race
Date: Sun, 18 Aug 2013 13:30:13 -0700 [thread overview]
Message-ID: <20130818202950.697108355@linuxfoundation.org> (raw)
In-Reply-To: <20130818202949.875887601@linuxfoundation.org>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <johannes.berg@intel.com>
commit 58ad436fcf49810aa006016107f494c9ac9013db upstream.
When dumping generic netlink families, only the first dump call
is locked with genl_lock(), which protects the list of families,
and thus subsequent calls can access the data without locking,
racing against family addition/removal. This can cause a crash.
Fix it - the locking needs to be conditional because the first
time around it's already locked.
A similar bug was reported to me on an old kernel (3.4.47) but
the exact scenario that happened there is no longer possible,
on those kernels the first round wasn't locked either. Looking
at the current code I found the race described above, which had
also existed on the old kernel.
Reported-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
net/netlink/genetlink.c | 7 +++++++
1 file changed, 7 insertions(+)
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -700,6 +700,10 @@ static int ctrl_dumpfamily(struct sk_buf
struct net *net = sock_net(skb->sk);
int chains_to_skip = cb->args[0];
int fams_to_skip = cb->args[1];
+ bool need_locking = chains_to_skip || fams_to_skip;
+
+ if (need_locking)
+ genl_lock();
for (i = chains_to_skip; i < GENL_FAM_TAB_SIZE; i++) {
n = 0;
@@ -721,6 +725,9 @@ errout:
cb->args[0] = i;
cb->args[1] = n;
+ if (need_locking)
+ genl_unlock();
+
return skb->len;
}
next prev parent reply other threads:[~2013-08-18 20:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-18 20:30 [ 00/12] 3.0.92-stable review Greg Kroah-Hartman
2013-08-18 20:30 ` [ 01/12] futex: Take hugepages into account when generating futex_key Greg Kroah-Hartman
2013-08-18 20:30 ` [ 02/12] CRIS: Add _sdata to vmlinux.lds.S Greg Kroah-Hartman
2013-08-18 20:30 ` [ 03/12] af_key: initialize satype in key_notify_policy_flush() Greg Kroah-Hartman
2013-08-18 20:30 ` Greg Kroah-Hartman [this message]
2013-08-18 20:30 ` [ 05/12] usb: add two quirky touchscreen Greg Kroah-Hartman
2013-08-18 20:30 ` [ 06/12] USB: mos7720: fix broken control requests Greg Kroah-Hartman
2013-08-18 20:30 ` [ 07/12] sparc32: add ucmpdi2 Greg Kroah-Hartman
2013-08-18 20:30 ` [ 08/12] sparc32: Add ucmpdi2.o to obj-y instead of lib-y Greg Kroah-Hartman
2013-08-18 20:30 ` [ 09/12] powerpc: Use -mtraceback=no Greg Kroah-Hartman
2013-08-18 20:30 ` [ 10/12] m68k/atari: ARAnyM - Fix NatFeat module support Greg Kroah-Hartman
2013-08-18 20:30 ` [ 11/12] ARM: 7080/1: l2x0: make sure I&D are not locked down on init Greg Kroah-Hartman
2013-08-18 20:30 ` [ 12/12] vm: add no-mmu vm_iomap_memory() stub Greg Kroah-Hartman
2013-08-18 20:37 ` [ 00/12] 3.0.92-stable review Geert Uytterhoeven
2013-08-18 20:52 ` Greg Kroah-Hartman
2013-08-19 1:39 ` Guenter Roeck
2013-08-19 22:53 ` Shuah Khan
2013-08-19 23:10 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130818202950.697108355@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=andrei.otcheretianski@intel.com \
--cc=davem@davemloft.net \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).