Skip to content

Commit

Permalink
gtp: fix a potential NULL pointer dereference
Browse files Browse the repository at this point in the history
[ Upstream commit defd8b3 ]

When sockfd_lookup() fails, gtp_encap_enable_socket() returns a
NULL pointer, but its callers only check for error pointers thus miss
the NULL pointer case.

Fix it by returning an error pointer with the error code carried from
sockfd_lookup().

(I found this bug during code inspection.)

Fixes: 1e3a3ab ("gtp: make GTP sockets in gtp_newlink optional")
Cc: Andreas Schultz <[email protected]>
Cc: Harald Welte <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Reviewed-by: Pablo Neira Ayuso <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Cong Wang authored and gregkh committed Sep 4, 2024
1 parent 56354b0 commit 612edd3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/net/gtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ static struct sock *gtp_encap_enable_socket(int fd, int type,
sock = sockfd_lookup(fd, &err);
if (!sock) {
pr_debug("gtp socket fd=%d not found\n", fd);
return NULL;
return ERR_PTR(err);
}

sk = sock->sk;
Expand Down

0 comments on commit 612edd3

Please sign in to comment.