From: "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Alexander Potapenko <glider@google.com>,
"David S . Miller" <davem@davemloft.net>,
"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Subject: [PATCH for 4.9 02/39] net/packet: check length in getsockopt() called with PACKET_HDRLEN
Date: Mon, 18 Sep 2017 00:19:37 +0000 [thread overview]
Message-ID: <20170918001922.7048-2-alexander.levin@verizon.com> (raw)
In-Reply-To: <20170918001922.7048-1-alexander.levin@verizon.com>
From: Alexander Potapenko <glider@google.com>
[ Upstream commit fd2c83b35752f0a8236b976978ad4658df14a59f ]
In the case getsockopt() is called with PACKET_HDRLEN and optlen < 4
|val| remains uninitialized and the syscall may behave differently
depending on its value, and even copy garbage to userspace on certain
architectures. To fix this we now return -EINVAL if optlen is too small.
This bug has been detected with KMSAN.
Signed-off-by: Alexander Potapenko <glider@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
net/packet/af_packet.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ae7bfd26cd91..2cf706f7defa 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3878,6 +3878,8 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
case PACKET_HDRLEN:
if (len > sizeof(int))
len = sizeof(int);
+ if (len < sizeof(int))
+ return -EINVAL;
if (copy_from_user(&val, optval, len))
return -EFAULT;
switch (val) {
--
2.11.0
next prev parent reply other threads:[~2017-09-18 0:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-18 0:19 [PATCH for 4.9 01/39] net: core: Prevent from dereferencing null pointer when releasing SKB Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` Levin, Alexander (Sasha Levin) [this message]
2017-09-18 0:19 ` [PATCH for 4.9 04/39] usb: plusb: Add support for PL-27A1 Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 03/39] team: fix memory leaks Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 08/39] mmc: sdio: fix alignment issue in struct sdio_func Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 05/39] udp: disable inner UDP checksum offloads in IPsec case Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 09/39] bridge: netlink: register netdevice before executing changelink Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 07/39] qed: Fix possible system hang in the dcbnl-getdcbx() path Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 06/39] net: dsa: b53: Include IMP/CPU port in dumb forwarding mode Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 12/39] sata_via: Enable hotplug only on VT6421 Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 11/39] Btrfs: fix potential use-after-free for cloned bio Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 10/39] Btrfs: fix segmentation fault when doing dio read Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 16/39] netfilter: invoke synchronize_rcu after set the _hook_ to NULL Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 15/39] drivers/rapidio/devices/tsi721.c: make module parameter variable name unique Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 13/39] hugetlbfs: initialize shared policy as part of inode allocation Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 14/39] kasan: do not sanitize kexec purgatory Levin, Alexander (Sasha Levin)
2017-09-18 0:19 ` [PATCH for 4.9 17/39] MIPS: IRQ Stack: Unwind IRQ stack onto task stack Levin, Alexander (Sasha Levin)
2017-09-18 6:41 ` [PATCH for 4.9 01/39] net: core: Prevent from dereferencing null pointer when releasing SKB Greg KH
2017-09-18 14:13 ` Levin, Alexander (Sasha Levin)
2017-09-18 14:31 ` Levin, Alexander (Sasha Levin)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170918001922.7048-2-alexander.levin@verizon.com \
--to=alexander.levin@verizon.com \
--cc=davem@davemloft.net \
--cc=glider@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®