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 08/11] af_unix: Set drop reason in manage_oob().
Date: Sun, 12 Jan 2025 13:08:07 +0900 [thread overview]
Message-ID: <20250112040810.14145-9-kuniyu@amazon.com> (raw)
In-Reply-To: <20250112040810.14145-1-kuniyu@amazon.com>
AF_UNIX SOCK_STREAM socket supports MSG_OOB.
When OOB data is sent to a socket, recv() will break at that point.
If the next recv() does not have MSG_OOB, the normal data following
the OOB data is returned.
Then, the OOB skb is dropped.
Let's define a new drop reason for that case in manage_oob().
# echo 1 > /sys/kernel/tracing/events/skb/kfree_skb/enable
# python3
>>> from socket import *
>>> s1, s2 = socketpair(AF_UNIX)
>>> s1.send(b'a', MSG_OOB)
>>> s1.send(b'b')
>>> s2.recv(2)
b'b'
# cat /sys/kernel/tracing/trace_pipe
...
python3-223 ... kfree_skb: ... location=unix_stream_read_generic+0x59e/0xc20 reason: UNIX_SKIP_OOB
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/dropreason-core.h | 6 ++++++
net/unix/af_unix.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index dea6bbe3ceaa..43e20acaa98a 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -12,6 +12,7 @@
FN(SOCKET_RCVBUFF) \
FN(SOCKET_RCV_SHUTDOWN) \
FN(UNIX_INFLIGHT_FD_LIMIT) \
+ FN(UNIX_SKIP_OOB) \
FN(PKT_TOO_SMALL) \
FN(TCP_CSUM) \
FN(UDP_CSUM) \
@@ -156,6 +157,11 @@ enum skb_drop_reason {
* are passed via SCM_RIGHTS but not yet received, reaching RLIMIT_NOFILE.
*/
SKB_DROP_REASON_UNIX_INFLIGHT_FD_LIMIT,
+ /**
+ * @SKB_DROP_REASON_UNIX_SKIP_OOB: Out-Of-Band data is skipped by
+ * recv() without MSG_OOB so dropped.
+ */
+ SKB_DROP_REASON_UNIX_SKIP_OOB,
/** @SKB_DROP_REASON_PKT_TOO_SMALL: packet size is too small */
SKB_DROP_REASON_PKT_TOO_SMALL,
/** @SKB_DROP_REASON_TCP_CSUM: TCP checksum error */
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 8623e3368c45..efd1b83b152a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2748,7 +2748,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
spin_unlock(&sk->sk_receive_queue.lock);
consume_skb(read_skb);
- kfree_skb(unread_skb);
+ kfree_skb_reason(unread_skb, SKB_DROP_REASON_UNIX_SKIP_OOB);
return skb;
}
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2025-01-12 4:12 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 ` [PATCH v2 net-next 07/11] af_unix: Set drop reason in queue_oob() Kuniyuki Iwashima
2025-01-12 4:08 ` Kuniyuki Iwashima [this message]
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-9-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).