Skip to content

Commit c8a75a5

Browse files
committed
af_unix: Use consume_skb() in connect() and sendmsg().
JIRA: https://issues.redhat.com/browse/RHEL-88891 Upstream Status: linux.git commit 085e6cb Author: Kuniyuki Iwashima <kuniyu@amazon.com> Date: Thu Jan 16 14:34:42 2025 +0900 af_unix: Use consume_skb() in connect() and sendmsg(). 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> Link: https://patch.msgid.link/20250116053441.5758-10-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent dcb4bf0 commit c8a75a5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

net/unix/af_unix.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
17061706
unix_state_unlock(other);
17071707
sock_put(other);
17081708
out_free_skb:
1709-
kfree_skb(skb);
1709+
consume_skb(skb);
17101710
out_free_sk:
17111711
unix_release_sock(newsk, 0);
17121712
out:
@@ -2174,7 +2174,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
21742174
unix_state_unlock(sk);
21752175
unix_state_unlock(other);
21762176
out_free:
2177-
kfree_skb(skb);
2177+
consume_skb(skb);
21782178
out:
21792179
if (other)
21802180
sock_put(other);
@@ -2193,33 +2193,30 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
21932193
{
21942194
struct unix_sock *ousk = unix_sk(other);
21952195
struct sk_buff *skb;
2196-
int err = 0;
2196+
int err;
21972197

21982198
skb = sock_alloc_send_skb(sock->sk, 1, msg->msg_flags & MSG_DONTWAIT, &err);
21992199

22002200
if (!skb)
22012201
return err;
22022202

22032203
err = unix_scm_to_skb(scm, skb, !fds_sent);
2204-
if (err < 0) {
2205-
kfree_skb(skb);
2206-
return err;
2207-
}
2204+
if (err < 0)
2205+
goto out;
2206+
22082207
skb_put(skb, 1);
22092208
err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, 1);
22102209

2211-
if (err) {
2212-
kfree_skb(skb);
2213-
return err;
2214-
}
2210+
if (err)
2211+
goto out;
22152212

22162213
unix_state_lock(other);
22172214

22182215
if (sock_flag(other, SOCK_DEAD) ||
22192216
(other->sk_shutdown & RCV_SHUTDOWN)) {
22202217
unix_state_unlock(other);
2221-
kfree_skb(skb);
2222-
return -EPIPE;
2218+
err = -EPIPE;
2219+
goto out;
22232220
}
22242221

22252222
maybe_add_creds(skb, sock, other);
@@ -2234,6 +2231,9 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
22342231
unix_state_unlock(other);
22352232
other->sk_data_ready(other);
22362233

2234+
return 0;
2235+
out:
2236+
consume_skb(skb);
22372237
return err;
22382238
}
22392239
#endif
@@ -2363,7 +2363,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
23632363
send_sig(SIGPIPE, current, 0);
23642364
err = -EPIPE;
23652365
out_free:
2366-
kfree_skb(skb);
2366+
consume_skb(skb);
23672367
out_err:
23682368
scm_destroy(&scm);
23692369
return sent ? : err;

0 commit comments

Comments
 (0)