[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250110092641.85905-9-kuniyu@amazon.com>
Date: Fri, 10 Jan 2025 18:26:37 +0900
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, Simon Horman <horms@...nel.org>
CC: Donald Hunter <donald.hunter@...hat.com>, Kuniyuki Iwashima
<kuniyu@...zon.com>, Kuniyuki Iwashima <kuni1840@...il.com>,
<netdev@...r.kernel.org>
Subject: [PATCH v1 net-next 08/12] af_unix: Set drop reason in queue_oob().
sendmsg(MSG_OOB) to a SOCK_STREAM socket could fail for various
reasons.
Let's set drop reasons respectively.
The drop reasons are exactly the same as in the previous patch.
Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
---
net/unix/af_unix.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 17b9e9bce055..1dfe791e8991 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2216,34 +2216,37 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
struct scm_cookie *scm, bool fds_sent)
{
struct unix_sock *ousk = unix_sk(other);
+ enum skb_drop_reason reason;
struct sk_buff *skb;
- int err = 0;
+ int err;
skb = sock_alloc_send_skb(sock->sk, 1, msg->msg_flags & MSG_DONTWAIT, &err);
-
if (!skb)
- return err;
+ goto out;
err = unix_scm_to_skb(scm, skb, !fds_sent);
if (err < 0) {
- kfree_skb(skb);
- return err;
+ reason = unix_scm_err_to_reason(err);
+ goto out_free;
}
+
skb_put(skb, 1);
err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, 1);
-
if (err) {
- kfree_skb(skb);
- return err;
+ reason = SKB_DROP_REASON_SKB_UCOPY_FAULT;
+ goto out_free;
}
unix_state_lock(other);
- if (sock_flag(other, SOCK_DEAD) ||
- (other->sk_shutdown & RCV_SHUTDOWN)) {
- unix_state_unlock(other);
- kfree_skb(skb);
- return -EPIPE;
+ if (sock_flag(other, SOCK_DEAD)) {
+ reason = SKB_DROP_REASON_SOCKET_CLOSE;
+ goto out_unlock;
+ }
+
+ if (other->sk_shutdown & RCV_SHUTDOWN) {
+ reason = SKB_DROP_REASON_SOCKET_RCV_SHUTDOWN;
+ goto out_unlock;
}
maybe_add_creds(skb, sock, other);
@@ -2258,6 +2261,14 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
unix_state_unlock(other);
other->sk_data_ready(other);
+ return 0;
+
+out_unlock:
+ unix_state_unlock(other);
+ err = -EPIPE;
+out_free:
+ kfree_skb_reason(skb, reason);
+out:
return err;
}
#endif
--
2.39.5 (Apple Git-154)
Powered by blists - more mailing lists