Skip to content

Commit 8163999

Browse files
jrfastabdavem330
authored andcommitted
bpf: skmsg, fix potential psock NULL pointer dereference
Report from Dan Carpenter, net/core/skmsg.c:792 sk_psock_write_space() error: we previously assumed 'psock' could be null (see line 790) net/core/skmsg.c 789 psock = sk_psock(sk); 790 if (likely(psock && sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED))) Check for NULL 791 schedule_work(&psock->work); 792 write_space = psock->saved_write_space; ^^^^^^^^^^^^^^^^^^^^^^^^ 793 rcu_read_unlock(); 794 write_space(sk); Ensure psock dereference on line 792 only occurs if psock is not null. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7599a89 commit 8163999

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/core/skmsg.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,18 @@ static void sk_psock_strp_data_ready(struct sock *sk)
793793
static void sk_psock_write_space(struct sock *sk)
794794
{
795795
struct sk_psock *psock;
796-
void (*write_space)(struct sock *sk);
796+
void (*write_space)(struct sock *sk) = NULL;
797797

798798
rcu_read_lock();
799799
psock = sk_psock(sk);
800-
if (likely(psock && sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)))
801-
schedule_work(&psock->work);
802-
write_space = psock->saved_write_space;
800+
if (likely(psock)) {
801+
if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED))
802+
schedule_work(&psock->work);
803+
write_space = psock->saved_write_space;
804+
}
803805
rcu_read_unlock();
804-
write_space(sk);
806+
if (write_space)
807+
write_space(sk);
805808
}
806809

807810
int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock)

0 commit comments

Comments
 (0)