]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: add copy_safe_from_sockptr() helper
authorEric Dumazet <edumazet@google.com>
Mon, 8 Apr 2024 08:28:43 +0000 (08:28 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 May 2024 10:14:45 +0000 (12:14 +0200)
commitf84429bdf255dc205416ae06561e6d81a735906c
treee0017c5201b987c957f9b77f35776a60213b2c3a
parent12b2e35e3f45fd254fec4dfaaa317b44612e56d3
net: add copy_safe_from_sockptr() helper

[ Upstream commit 6309863b31dd80317cd7d6824820b44e254e2a9c ]

copy_from_sockptr() helper is unsafe, unless callers
did the prior check against user provided optlen.

Too many callers get this wrong, lets add a helper to
fix them and avoid future copy/paste bugs.

Instead of :

   if (optlen < sizeof(opt)) {
       err = -EINVAL;
       break;
   }
   if (copy_from_sockptr(&opt, optval, sizeof(opt)) {
       err = -EFAULT;
       break;
   }

Use :

   err = copy_safe_from_sockptr(&opt, sizeof(opt),
                                optval, optlen);
   if (err)
       break;

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240408082845.3957374-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/sockptr.h