[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f162bcec-7c13-47f0-b784-77e0c3e2c766@kadam.mountain>
Date: Wed, 13 Sep 2023 10:19:23 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: oe-kbuild@...ts.linux.dev, Jordan Rife <jrife@...gle.com>,
davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, netdev@...r.kernel.org
Cc: lkp@...el.com, oe-kbuild-all@...ts.linux.dev, dborkman@...nel.org,
Jordan Rife <jrife@...gle.com>
Subject: Re: [PATCH net] net: prevent address overwrite in connect() and
sendmsg()
Hi Jordan,
kernel test robot noticed the following build warnings:
url: https://github.com/intel-lab-lkp/linux/commits/Jordan-Rife/net-prevent-address-overwrite-in-connect-and-sendmsg/20230912-093550
base: net/main
patch link: https://lore.kernel.org/r/20230912013332.2048422-1-jrife%40google.com
patch subject: [PATCH net] net: prevent address overwrite in connect() and sendmsg()
config: x86_64-randconfig-161-20230912 (https://download.01.org/0day-ci/archive/20230913/202309131155.MonA0VTS-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230913/202309131155.MonA0VTS-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@...el.com>
| Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
| Closes: https://lore.kernel.org/r/202309131155.MonA0VTS-lkp@intel.com/
smatch warnings:
net/ipv4/af_inet.c:584 inet_dgram_connect() warn: variable dereferenced before check 'uaddr' (see line 580)
vim +/uaddr +584 net/ipv4/af_inet.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 566 int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
^1da177e4c3f41 Linus Torvalds 2005-04-16 567 int addr_len, int flags)
^1da177e4c3f41 Linus Torvalds 2005-04-16 568 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 569 struct sock *sk = sock->sk;
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 570 const struct proto *prot;
6113a07e1ad512 Jordan Rife 2023-09-11 571 struct sockaddr_storage addr;
d74bad4e74ee37 Andrey Ignatov 2018-03-30 572 int err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 573
6503d96168f891 Changli Gao 2010-03-31 574 if (addr_len < sizeof(uaddr->sa_family))
6503d96168f891 Changli Gao 2010-03-31 575 return -EINVAL;
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 576
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 577 /* IPV6_ADDRFORM can change sk->sk_prot under us. */
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 578 prot = READ_ONCE(sk->sk_prot);
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 579
^1da177e4c3f41 Linus Torvalds 2005-04-16 @580 if (uaddr->sa_family == AF_UNSPEC)
^^^^^^^^^^^^^^^^
"uaddr" better not be NULL
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 581 return prot->disconnect(sk, flags);
^1da177e4c3f41 Linus Torvalds 2005-04-16 582
d74bad4e74ee37 Andrey Ignatov 2018-03-30 583 if (BPF_CGROUP_PRE_CONNECT_ENABLED(sk)) {
6113a07e1ad512 Jordan Rife 2023-09-11 @584 if (uaddr && addr_len <= sizeof(addr)) {
^^^^^
Remove this check?
6113a07e1ad512 Jordan Rife 2023-09-11 585 /* pre_connect can rewrite uaddr, so make a copy to
6113a07e1ad512 Jordan Rife 2023-09-11 586 * insulate the caller.
6113a07e1ad512 Jordan Rife 2023-09-11 587 */
6113a07e1ad512 Jordan Rife 2023-09-11 588 memcpy(&addr, uaddr, addr_len);
6113a07e1ad512 Jordan Rife 2023-09-11 589 uaddr = (struct sockaddr *)&addr;
6113a07e1ad512 Jordan Rife 2023-09-11 590 }
6113a07e1ad512 Jordan Rife 2023-09-11 591
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 592 err = prot->pre_connect(sk, uaddr, addr_len);
d74bad4e74ee37 Andrey Ignatov 2018-03-30 593 if (err)
d74bad4e74ee37 Andrey Ignatov 2018-03-30 594 return err;
d74bad4e74ee37 Andrey Ignatov 2018-03-30 595 }
d74bad4e74ee37 Andrey Ignatov 2018-03-30 596
dcd01eeac14486 Eric Dumazet 2021-06-09 597 if (data_race(!inet_sk(sk)->inet_num) && inet_autobind(sk))
^1da177e4c3f41 Linus Torvalds 2005-04-16 598 return -EAGAIN;
364f997b5cfe1d Kuniyuki Iwashima 2022-10-06 599 return prot->connect(sk, uaddr, addr_len);
^1da177e4c3f41 Linus Torvalds 2005-04-16 600 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Powered by blists - more mailing lists