netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Cc: Donald Hunter <donald.hunter@redhat.com>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v2 net-next 07/11] af_unix: Set drop reason in queue_oob().
Date: Sun, 12 Jan 2025 13:08:06 +0900	[thread overview]
Message-ID: <20250112040810.14145-8-kuniyu@amazon.com> (raw)
In-Reply-To: <20250112040810.14145-1-kuniyu@amazon.com>

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@amazon.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 8c8d8fc3cb94..8623e3368c45 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)


  parent reply	other threads:[~2025-01-12  4:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-12  4:07 [PATCH v2 net-next 00/11] af_unix: Set skb drop reason in every kfree_skb() path Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 01/11] net: dropreason: Gather SOCKET_ drop reasons Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 02/11] af_unix: Set drop reason in unix_release_sock() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 03/11] af_unix: Set drop reason in unix_sock_destructor() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 04/11] af_unix: Set drop reason in __unix_gc() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 05/11] af_unix: Set drop reason in unix_stream_connect() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 06/11] af_unix: Set drop reason in unix_stream_sendmsg() Kuniyuki Iwashima
2025-01-15  1:05   ` Jakub Kicinski
2025-01-15 13:52     ` Donald Hunter
2025-01-15 15:12       ` Paolo Abeni
2025-01-16  4:09         ` Kuniyuki Iwashima
2025-01-12  4:08 ` Kuniyuki Iwashima [this message]
2025-01-12  4:08 ` [PATCH v2 net-next 08/11] af_unix: Set drop reason in manage_oob() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 09/11] af_unix: Set drop reason in unix_stream_read_skb() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 10/11] af_unix: Set drop reason in unix_dgram_disconnected() Kuniyuki Iwashima
2025-01-12  4:08 ` [PATCH v2 net-next 11/11] af_unix: Set drop reason in unix_dgram_sendmsg() Kuniyuki Iwashima
2025-01-15 17:38 ` [PATCH v2 net-next 00/11] af_unix: Set skb drop reason in every kfree_skb() path Joe Damato
2025-01-16  4:19   ` Kuniyuki Iwashima

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=20250112040810.14145-8-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@redhat.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).