]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
gtp: fix a potential NULL pointer dereference
authorCong Wang <cong.wang@bytedance.com>
Sun, 25 Aug 2024 19:16:38 +0000 (12:16 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 27 Aug 2024 21:19:40 +0000 (14:19 -0700)
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: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional")
Cc: Andreas Schultz <aschultz@tpip.net>
Cc: Harald Welte <laforge@gnumonks.org>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
Link: https://patch.msgid.link/20240825191638.146748-1-xiyou.wangcong@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/gtp.c

index 0696faf60013e0669ceb4aa39dfbac17ad741540..2e94d10348ccebf6e663032bb587cedcefbc82f1 100644 (file)
@@ -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;