Skip to content

Commit fef0035

Browse files
zx2c4davem330
authored andcommitted
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>
1 parent 3e7e072 commit fef0035

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

net/netlink/af_netlink.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,10 +2270,13 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
22702270

22712271
mutex_unlock(nlk->cb_mutex);
22722272

2273+
ret = 0;
22732274
if (cb->start)
2274-
cb->start(cb);
2275+
ret = cb->start(cb);
2276+
2277+
if (!ret)
2278+
ret = netlink_dump(sk);
22752279

2276-
ret = netlink_dump(sk);
22772280
sock_put(sk);
22782281

22792282
if (ret)

0 commit comments

Comments
 (0)