B.A.T.M.A.N Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 06/12] batctl: netlink: report kernel errors when writing settings
Date: Wed, 08 Jul 2026 22:00:12 +0200	[thread overview]
Message-ID: <20260708-bugfixes-netlink-v1-6-8ce03e37f17b@narfation.org> (raw)
In-Reply-To: <20260708-bugfixes-netlink-v1-0-8ce03e37f17b@narfation.org>

When writing a setting, sys_simple_nlquery() consumes the kernel reply via
nl_wait_for_ack(). This helper uses the socket's default callbacks instead
of state->cb, so sys_simple_nlerror() never runs and its (negative) return
value is discarded. A set request rejected by the kernel therefore prints
no error message and exits with EXIT_SUCCESS.

This can be seen easily by calling: "batctl meshif bat0 aggregation 1"
without CAP_NET_ADMIN.

Receive the reply through state->cb instead, like the read path already
does. The error handler then prints the kernel error, stores it in result
and the command exits with EXIT_FAILURE.

Fixes: 0b81e8fbaed5 ("batctl: Consume genl ACKs after setting reads")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 sys.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sys.c b/sys.c
index 35a026e..a4d531f 100644
--- a/sys.c
+++ b/sys.c
@@ -110,10 +110,16 @@ int sys_simple_nlquery(struct state *state, enum batadv_nl_commands nl_cmd,
 	if (callback) {
 		ret = nl_recvmsgs(state->sock, state->cb);
 		if (ret < 0)
-			return ret;
+			return -EIO;
+
+		nl_wait_for_ack(state->sock);
+
+		return result;
 	}
 
-	nl_wait_for_ack(state->sock);
+	ret = nl_recvmsgs(state->sock, state->cb);
+	if (ret < 0 && result >= 0)
+		result = -EIO;
 
 	return result;
 }

-- 
2.47.3


  parent reply	other threads:[~2026-07-08 20:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 20:00 [PATCH 00/12] batctl: netlink bugfixes Sven Eckelmann
2026-07-08 20:00 ` [PATCH 01/12] batctl: handle netlink callback object on error Sven Eckelmann
2026-07-08 20:00 ` [PATCH 02/12] batctl: netlink: abort netlink_print_common when message allocation fails Sven Eckelmann
2026-07-08 20:00 ` [PATCH 03/12] batctl: netlink: don't format NULL extra_info in info_callback Sven Eckelmann
2026-07-08 20:00 ` [PATCH 04/12] batctl: netlink: report dump errors signalled in the NLMSG_DONE message Sven Eckelmann
2026-07-08 20:00 ` [PATCH 05/12] batctl: netlink: detect receive errors in netlink_print_common Sven Eckelmann
2026-07-08 20:00 ` Sven Eckelmann [this message]
2026-07-08 20:00 ` [PATCH 07/12] batctl: netlink: report send errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` [PATCH 08/12] batctl: netlink: detect receive errors in query_rtnl_link Sven Eckelmann
2026-07-08 20:00 ` [PATCH 09/12] batctl: netlink: detect receive errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` [PATCH 10/12] batctl: netlink: detect receive errors in query_rtnl_link_single Sven Eckelmann
2026-07-08 20:00 ` [PATCH 11/12] batctl: netlink: report error on query_rtnl_link send failure Sven Eckelmann
2026-07-08 20:00 ` [PATCH 12/12] batctl: netlink: use kernel-style error codes for nl_recvmsgs Sven Eckelmann

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=20260708-bugfixes-netlink-v1-6-8ce03e37f17b@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.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