Skip to content

Commit 7a0f943

Browse files
committed
net: psp: don't assume reply skbs will have a socket
Rx path may be passing around unreferenced sockets, which means that skb_set_owner_edemux() may not set skb->sk and PSP will crash: KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:psp_reply_set_decrypted (./include/net/psp/functions.h:132 net/psp/psp_sock.c:287) tcp_v6_send_response.constprop.0 (net/ipv6/tcp_ipv6.c:979) tcp_v6_send_reset (net/ipv6/tcp_ipv6.c:1140 (discriminator 1)) tcp_v6_do_rcv (net/ipv6/tcp_ipv6.c:1683) tcp_v6_rcv (net/ipv6/tcp_ipv6.c:1912) Fixes: 659a289 ("tcp: add datapath logic for PSP with inline key exchange") Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20251001022426.2592750-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 4f0d91b commit 7a0f943

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

include/net/psp/functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ unsigned int psp_key_size(u32 version);
3434
void psp_sk_assoc_free(struct sock *sk);
3535
void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk);
3636
void psp_twsk_assoc_free(struct inet_timewait_sock *tw);
37-
void psp_reply_set_decrypted(struct sk_buff *skb);
37+
void psp_reply_set_decrypted(const struct sock *sk, struct sk_buff *skb);
3838

3939
static inline struct psp_assoc *psp_sk_assoc(const struct sock *sk)
4040
{
@@ -160,7 +160,7 @@ static inline void
160160
psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk) { }
161161
static inline void psp_twsk_assoc_free(struct inet_timewait_sock *tw) { }
162162
static inline void
163-
psp_reply_set_decrypted(struct sk_buff *skb) { }
163+
psp_reply_set_decrypted(const struct sock *sk, struct sk_buff *skb) { }
164164

165165
static inline struct psp_assoc *psp_sk_assoc(const struct sock *sk)
166166
{

net/ipv4/ip_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ void ip_send_unicast_reply(struct sock *sk, const struct sock *orig_sk,
16681668
nskb->ip_summed = CHECKSUM_NONE;
16691669
if (orig_sk) {
16701670
skb_set_owner_edemux(nskb, (struct sock *)orig_sk);
1671-
psp_reply_set_decrypted(nskb);
1671+
psp_reply_set_decrypted(orig_sk, nskb);
16721672
}
16731673
if (transmit_time)
16741674
nskb->tstamp_type = SKB_CLOCK_MONOTONIC;

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
974974
if (sk) {
975975
/* unconstify the socket only to attach it to buff with care. */
976976
skb_set_owner_edemux(buff, (struct sock *)sk);
977-
psp_reply_set_decrypted(buff);
977+
psp_reply_set_decrypted(sk, buff);
978978

979979
if (sk->sk_state == TCP_TIME_WAIT)
980980
mark = inet_twsk(sk)->tw_mark;

net/psp/psp_sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ void psp_twsk_assoc_free(struct inet_timewait_sock *tw)
279279
psp_assoc_put(pas);
280280
}
281281

282-
void psp_reply_set_decrypted(struct sk_buff *skb)
282+
void psp_reply_set_decrypted(const struct sock *sk, struct sk_buff *skb)
283283
{
284284
struct psp_assoc *pas;
285285

286286
rcu_read_lock();
287-
pas = psp_sk_get_assoc_rcu(skb->sk);
287+
pas = psp_sk_get_assoc_rcu(sk);
288288
if (pas && pas->tx.spi)
289289
skb->decrypted = 1;
290290
rcu_read_unlock();

0 commit comments

Comments
 (0)