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 v3 net-next 9/9] af_unix: Use consume_skb() in connect() and sendmsg().
Date: Thu, 16 Jan 2025 14:34:42 +0900 [thread overview]
Message-ID: <20250116053441.5758-10-kuniyu@amazon.com> (raw)
In-Reply-To: <20250116053441.5758-1-kuniyu@amazon.com>
This is based on Donald Hunter's patch.
These functions could fail for various reasons, sometimes
triggering kfree_skb().
* unix_stream_connect() : connect()
* unix_stream_sendmsg() : sendmsg()
* queue_oob() : sendmsg(MSG_OOB)
* unix_dgram_sendmsg() : sendmsg()
Such kfree_skb() is tied to the errno of connect() and
sendmsg(), and we need not define skb drop reasons.
Let's use consume_skb() not to churn kfree_skb() events.
Link: https://lore.kernel.org/netdev/eb30b164-7f86-46bf-a5d3-0f8bda5e9398@redhat.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/unix/af_unix.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 43a45cf06f2e..34945de1fb1f 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1701,7 +1701,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
unix_state_unlock(other);
sock_put(other);
out_free_skb:
- kfree_skb(skb);
+ consume_skb(skb);
out_free_sk:
unix_release_sock(newsk, 0);
out:
@@ -2172,7 +2172,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
out_sock_put:
sock_put(other);
out_free:
- kfree_skb(skb);
+ consume_skb(skb);
out:
scm_destroy(&scm);
return err;
@@ -2189,7 +2189,7 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
{
struct unix_sock *ousk = unix_sk(other);
struct sk_buff *skb;
- int err = 0;
+ int err;
skb = sock_alloc_send_skb(sock->sk, 1, msg->msg_flags & MSG_DONTWAIT, &err);
@@ -2197,25 +2197,22 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
return err;
err = unix_scm_to_skb(scm, skb, !fds_sent);
- if (err < 0) {
- kfree_skb(skb);
- return err;
- }
+ if (err < 0)
+ goto out;
+
skb_put(skb, 1);
err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, 1);
- if (err) {
- kfree_skb(skb);
- return err;
- }
+ if (err)
+ goto out;
unix_state_lock(other);
if (sock_flag(other, SOCK_DEAD) ||
(other->sk_shutdown & RCV_SHUTDOWN)) {
unix_state_unlock(other);
- kfree_skb(skb);
- return -EPIPE;
+ err = -EPIPE;
+ goto out;
}
maybe_add_creds(skb, sock, other);
@@ -2230,6 +2227,9 @@ 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:
+ consume_skb(skb);
return err;
}
#endif
@@ -2359,7 +2359,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
send_sig(SIGPIPE, current, 0);
err = -EPIPE;
out_free:
- kfree_skb(skb);
+ consume_skb(skb);
out_err:
scm_destroy(&scm);
return sent ? : err;
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2025-01-16 5:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 5:34 [PATCH v3 net-next 0/9] af_unix: Set skb drop reason in every kfree_skb() path Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 1/9] net: dropreason: Gather SOCKET_ drop reasons Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 2/9] af_unix: Set drop reason in unix_release_sock() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 3/9] af_unix: Set drop reason in unix_sock_destructor() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 4/9] af_unix: Set drop reason in __unix_gc() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 5/9] af_unix: Set drop reason in manage_oob() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 6/9] af_unix: Set drop reason in unix_stream_read_skb() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 7/9] af_unix: Set drop reason in unix_dgram_disconnected() Kuniyuki Iwashima
2025-01-16 5:34 ` [PATCH v3 net-next 8/9] af_unix: Reuse out_pipe label in unix_stream_sendmsg() Kuniyuki Iwashima
2025-01-16 5:34 ` Kuniyuki Iwashima [this message]
2025-01-20 19:50 ` [PATCH v3 net-next 0/9] af_unix: Set skb drop reason in every kfree_skb() path patchwork-bot+netdevbpf
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=20250116053441.5758-10-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).