Re: [PATCH] netlink: invert error code in netlink_set_err()

Previous thread: Bluetooth oops from hci_conn_del, kernel 2.6.29-rc6 by Chuck Ebbert on Tuesday, March 3, 2009 - 3:43 pm. (2 messages)

Next thread: [net-next PATCH 1/2] PCI: Add PCI quirk to disable L0s ASPM state for 82575 and 82598 by Jeff Kirsher on Tuesday, March 3, 2009 - 7:03 pm. (6 messages)
From: Pablo Neira Ayuso
Date: Tuesday, March 3, 2009 - 4:35 pm

The callers of netlink_set_err() currently pass a negative value
as parameter for the error code. However, sk->sk_err wants a
positive error value. Without this patch, skb_recv_datagram() called
by netlink_recvmsg() may return a positive value to report an error.

Another choice to fix this is to change callers to pass a positive
error value, but this seems a bit inconsistent and error prone
to me. Indeed, the callers of netlink_set_err() assumed that the
(usual) negative value for error codes was fine before this patch :).

This patch also includes some documentation in docbook format
for netlink_set_err() to avoid this sort of confusion.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---

 net/netlink/af_netlink.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 2760b62..09e5008 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1092,6 +1092,13 @@ out:
 	return 0;
 }
 
+/**
+ * netlink_set_err - report error to broadcast listeners
+ * @ssk: the kernel netlink socket, as returned by netlink_kernel_create()
+ * @pid: the PID of a process that we want to skip (if any)
+ * @groups: the broadcast group that will notice the error
+ * @code: error code, must be negative (as usual in kernelspace)
+ */
 void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
 {
 	struct netlink_set_err_data info;
@@ -1101,7 +1108,8 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
 	info.exclude_sk = ssk;
 	info.pid = pid;
 	info.group = group;
-	info.code = code;
+	/* sk->sk_err wants a positive error value */
+	info.code = -code;
 
 	read_lock(&nl_table_lock);
 

--

From: David Miller
Date: Wednesday, March 4, 2009 - 12:37 am

From: Pablo Neira Ayuso <pablo@netfilter.org>

Applied, thanks a lot Pablo.
--

From: Patrick McHardy
Date: Wednesday, March 4, 2009 - 3:13 am

Amazing how this kept hidden for so long. I could have sworn I've
already seen the notification errors in userspace :)
--

Previous thread: Bluetooth oops from hci_conn_del, kernel 2.6.29-rc6 by Chuck Ebbert on Tuesday, March 3, 2009 - 3:43 pm. (2 messages)

Next thread: [net-next PATCH 1/2] PCI: Add PCI quirk to disable L0s ASPM state for 82575 and 82598 by Jeff Kirsher on Tuesday, March 3, 2009 - 7:03 pm. (6 messages)