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 <[email protected]>
---
 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

Reply via email to