Skip to content

Commit 085e6cb

Browse files
q2venkuba-moo
authored andcommitted
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>
1 parent 3b2d40d commit 085e6cb

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
@@ -1701,7 +1701,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
17011701
unix_state_unlock(other);
17021702
sock_put(other);
17031703
out_free_skb:
1704-
kfree_skb(skb);
1704+
consume_skb(skb);
17051705
out_free_sk:
17061706
unix_release_sock(newsk, 0);
17071707
out:
@@ -2172,7 +2172,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
21722172
out_sock_put:
21732173
sock_put(other);
21742174
out_free:
2175-
kfree_skb(skb);
2175+
consume_skb(skb);
21762176
out:
21772177
scm_destroy(&scm);
21782178
return err;
@@ -2189,33 +2189,30 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
21892189
{
21902190
struct unix_sock *ousk = unix_sk(other);
21912191
struct sk_buff *skb;
2192-
int err = 0;
2192+
int err;
21932193

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

21962196
if (!skb)
21972197
return err;
21982198

21992199
err = unix_scm_to_skb(scm, skb, !fds_sent);
2200-
if (err < 0) {
2201-
kfree_skb(skb);
2202-
return err;
2203-
}
2200+
if (err < 0)
2201+
goto out;
2202+
22042203
skb_put(skb, 1);
22052204
err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, 1);
22062205

2207-
if (err) {
2208-
kfree_skb(skb);
2209-
return err;
2210-
}
2206+
if (err)
2207+
goto out;
22112208

22122209
unix_state_lock(other);
22132210

22142211
if (sock_flag(other, SOCK_DEAD) ||
22152212
(other->sk_shutdown & RCV_SHUTDOWN)) {
22162213
unix_state_unlock(other);
2217-
kfree_skb(skb);
2218-
return -EPIPE;
2214+
err = -EPIPE;
2215+
goto out;
22192216
}
22202217

22212218
maybe_add_creds(skb, sock, other);
@@ -2230,6 +2227,9 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
22302227
unix_state_unlock(other);
22312228
other->sk_data_ready(other);
22322229

2230+
return 0;
2231+
out:
2232+
consume_skb(skb);
22332233
return err;
22342234
}
22352235
#endif
@@ -2359,7 +2359,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
23592359
send_sig(SIGPIPE, current, 0);
23602360
err = -EPIPE;
23612361
out_free:
2362-
kfree_skb(skb);
2362+
consume_skb(skb);
23632363
out_err:
23642364
scm_destroy(&scm);
23652365
return sent ? : err;

0 commit comments

Comments
 (0)