Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netlink: do not proceed if dump's start() errs

Drivers that use the start method for netlink dumping rely on dumpit not
being called if start fails. For example, ila_xlat.c allocates memory
and assigns it to cb->args[0] in its start() function. It might fail to
do that and return -ENOMEM instead. However, even when returning an
error, dumpit will be called, which, in the example above, quickly
dereferences the memory in cb->args[0], which will OOPS the kernel. This
is but one example of how this goes wrong.

Since start() has always been a function with an int return type, it
therefore makes sense to use it properly, rather than ignoring it. This
patch thus returns early and does not call dumpit() when start() fails.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jason A. Donenfeld and committed by
David S. Miller
fef0035c 3e7e0728

+5 -2
+5 -2
net/netlink/af_netlink.c
··· 2270 2270 2271 2271 mutex_unlock(nlk->cb_mutex); 2272 2272 2273 + ret = 0; 2273 2274 if (cb->start) 2274 - cb->start(cb); 2275 + ret = cb->start(cb); 2275 2276 2276 - ret = netlink_dump(sk); 2277 + if (!ret) 2278 + ret = netlink_dump(sk); 2279 + 2277 2280 sock_put(sk); 2278 2281 2279 2282 if (ret)