handshake: Fix sign of socket file descriptor fields
authorChuck Lever <chuck.lever@oracle.com>
Thu, 21 Sep 2023 13:07:40 +0000 (09:07 -0400)
committerJakub Kicinski <kuba@kernel.org>
Mon, 2 Oct 2023 19:34:21 +0000 (12:34 -0700)
Socket file descriptors are signed integers. Use nla_get/put_s32 for
those to avoid implicit signed conversion in the netlink protocol.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/169530165057.8905.8650469415145814828.stgit@oracle-102.nfsv4bat.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/netlink/specs/handshake.yaml
net/handshake/genl.c
net/handshake/netlink.c
net/handshake/tlshd.c
tools/net/ynl/generated/handshake-user.h

index 6d89e30f5fd52b1bfe7c1f36f9b5a859ccccfc2b..a49b46b80e1650385e17d6c5ab382dd0f5f67301 100644 (file)
@@ -43,7 +43,7 @@ attribute-sets:
     attributes:
       -
         name: sockfd
-        type: u32
+        type: s32
       -
         name: handler-class
         type: u32
@@ -79,7 +79,7 @@ attribute-sets:
         type: u32
       -
         name: sockfd
-        type: u32
+        type: s32
       -
         name: remote-auth
         type: u32
index 233be5cbfec91a02647fad5c5b786b6982e0f33e..f55d14d7b7269d40b5d41a0d4d06272ce083b50e 100644 (file)
@@ -18,7 +18,7 @@ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HAN
 /* HANDSHAKE_CMD_DONE - do */
 static const struct nla_policy handshake_done_nl_policy[HANDSHAKE_A_DONE_REMOTE_AUTH + 1] = {
        [HANDSHAKE_A_DONE_STATUS] = { .type = NLA_U32, },
-       [HANDSHAKE_A_DONE_SOCKFD] = { .type = NLA_U32, },
+       [HANDSHAKE_A_DONE_SOCKFD] = { .type = NLA_S32, },
        [HANDSHAKE_A_DONE_REMOTE_AUTH] = { .type = NLA_U32, },
 };
 
index d0bc1dd8e65a8201751fddcc2356da89cd2c65e7..64a0046dd611c1300a5749455da62a30606783c4 100644 (file)
@@ -163,7 +163,7 @@ int handshake_nl_done_doit(struct sk_buff *skb, struct genl_info *info)
 
        if (GENL_REQ_ATTR_CHECK(info, HANDSHAKE_A_DONE_SOCKFD))
                return -EINVAL;
-       fd = nla_get_u32(info->attrs[HANDSHAKE_A_DONE_SOCKFD]);
+       fd = nla_get_s32(info->attrs[HANDSHAKE_A_DONE_SOCKFD]);
 
        sock = sockfd_lookup(fd, &err);
        if (!sock)
index bbfb4095ddd6b46aea1a1619214d5741c31c5162..7ac80201aa1fc29857cc631add551cf8743e8e89 100644 (file)
@@ -214,7 +214,7 @@ static int tls_handshake_accept(struct handshake_req *req,
                goto out_cancel;
 
        ret = -EMSGSIZE;
-       ret = nla_put_u32(msg, HANDSHAKE_A_ACCEPT_SOCKFD, fd);
+       ret = nla_put_s32(msg, HANDSHAKE_A_ACCEPT_SOCKFD, fd);
        if (ret < 0)
                goto out_cancel;
        ret = nla_put_u32(msg, HANDSHAKE_A_ACCEPT_MESSAGE_TYPE, treq->th_type);
index 47646bb91cea69a2da76fcd2033d72fa0454ecb4..f8e481fa9e09b20188cee77274476692f4fc4662 100644 (file)
@@ -65,7 +65,7 @@ struct handshake_accept_rsp {
                __u32 peername_len;
        } _present;
 
-       __u32 sockfd;
+       __s32 sockfd;
        enum handshake_msg_type message_type;
        __u32 timeout;
        enum handshake_auth auth_mode;
@@ -104,7 +104,7 @@ struct handshake_done_req {
        } _present;
 
        __u32 status;
-       __u32 sockfd;
+       __s32 sockfd;
        unsigned int n_remote_auth;
        __u32 *remote_auth;
 };
@@ -122,7 +122,7 @@ handshake_done_req_set_status(struct handshake_done_req *req, __u32 status)
        req->status = status;
 }
 static inline void
-handshake_done_req_set_sockfd(struct handshake_done_req *req, __u32 sockfd)
+handshake_done_req_set_sockfd(struct handshake_done_req *req, __s32 sockfd)
 {
        req->_present.sockfd = 1;
        req->sockfd = sockfd;