Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2792471ybv; Mon, 24 Feb 2020 11:42:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwSeavvjz/ztwo5BQJ/bBE2et8U5fAA3RbgOqGMvEcqLMnw1wMHx4+RYrMf+mUtCssPAAkD X-Received: by 2002:a9d:7d93:: with SMTP id j19mr43403518otn.102.1582573363163; Mon, 24 Feb 2020 11:42:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582573363; cv=none; d=google.com; s=arc-20160816; b=vkAbTzul9gbWu+u/Gigb/EOT8HMjAzz5VSfqk63ZC9zsbFG2JtprOO5j6a+kmF24+H AYI25RKl0cuiO8g3NFEYB/p8oaN0va0OTvcp4uOjh7hyfol/OBpdtu1pErKQnBQtvAh2 jyTBI7ZKkCELGhqaVhm3Dng14GIUiYUCEB1c10GZKrvVd2gosb9K/3E+ZivkARoin0Kb /FjfETYBPSnl55PLGDr8plPK1Bf/j4GhZFycyOwy2vJu8mjGnIoNgeOK3sluhucxSySN ghvhx9g2SZNXbVx7AIvLFhzlD77EJr/otSkZ61VGMQpAZsg4cUY35Uzg4nepn66cNfg5 rqtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from; bh=iOhS0uDTJOXd1EPNMb/FCUBAGigagKwCVEvsWOSC32I=; b=Y4kc1qpqkno+F73ypyRNtO5M5ZLmurj0d4XfNppQto5gLB/cJO0xoxyjvPi5R+U1p6 hD5rvxCDzHB+U9quoo7Pe7ZGe3QI7HspG0Up3P0Btc1Whk3TFLbufT0seQLXkCk26mOi uET29Gn/PWaPPofqDmX/cbADfmsWNCxnP3d4o94Q/jWLXvvH2QZXwkqlWdkVB28+4znI rM/EtMdSbJqE/HYbcyX+MwkKUBfyWgvSiWQ3oIZw61WiD8ta7jm1eBOO83X1LowdzUqO KDryClar1x8PY+WUFup41By8u3Wy5ir6xVdd+EL9ssCwyQ9g3wineZTp6rHL8ti4XPhv 1poQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si5109965oie.15.2020.02.24.11.42.30; Mon, 24 Feb 2020 11:42:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbgBXTmP (ORCPT + 99 others); Mon, 24 Feb 2020 14:42:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:35926 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbgBXTmO (ORCPT ); Mon, 24 Feb 2020 14:42:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 14C45AD8E; Mon, 24 Feb 2020 19:42:12 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 426B4E1E06; Mon, 24 Feb 2020 20:42:12 +0100 (CET) From: Michal Kubecek Subject: [PATCH net] ethtool: limit bitset size To: "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Message-Id: <20200224194212.426B4E1E06@unicorn.suse.cz> Date: Mon, 24 Feb 2020 20:42:12 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Syzbot reported that ethnl_compact_sanity_checks() can be tricked into reading past the end of ETHTOOL_A_BITSET_VALUE and ETHTOOL_A_BITSET_MASK attributes and even the message by passing a value between (u32)(-31) and (u32)(-1) as ETHTOOL_A_BITSET_SIZE. The problem is that DIV_ROUND_UP(attr_nbits, 32) is 0 for such values so that zero length ETHTOOL_A_BITSET_VALUE will pass the length check but ethnl_bitmap32_not_zero() check would try to access up to 512 MB of attribute "payload". Prevent this overflow byt limiting the bitset size. Technically, compact bitset format would allow bitset sizes up to almost 2^18 (so that the nest size does not exceed U16_MAX) but bitsets used by ethtool are much shorter. S16_MAX, the largest value which can be directly used as an upper limit in policy, should be a reasonable compromise. Fixes: 10b518d4e6dd ("ethtool: netlink bitset handling") Reported-by: syzbot+7fd4ed5b4234ab1fdccd@syzkaller.appspotmail.com Reported-by: syzbot+709b7a64d57978247e44@syzkaller.appspotmail.com Reported-by: syzbot+983cb8fb2d17a7af549d@syzkaller.appspotmail.com Signed-off-by: Michal Kubecek --- net/ethtool/bitset.c | 3 ++- net/ethtool/bitset.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c index 8977fe1f3946..ef9197541cb3 100644 --- a/net/ethtool/bitset.c +++ b/net/ethtool/bitset.c @@ -305,7 +305,8 @@ int ethnl_put_bitset32(struct sk_buff *skb, int attrtype, const u32 *val, static const struct nla_policy bitset_policy[ETHTOOL_A_BITSET_MAX + 1] = { [ETHTOOL_A_BITSET_UNSPEC] = { .type = NLA_REJECT }, [ETHTOOL_A_BITSET_NOMASK] = { .type = NLA_FLAG }, - [ETHTOOL_A_BITSET_SIZE] = { .type = NLA_U32 }, + [ETHTOOL_A_BITSET_SIZE] = NLA_POLICY_MAX(NLA_U32, + ETHNL_MAX_BITSET_SIZE), [ETHTOOL_A_BITSET_BITS] = { .type = NLA_NESTED }, [ETHTOOL_A_BITSET_VALUE] = { .type = NLA_BINARY }, [ETHTOOL_A_BITSET_MASK] = { .type = NLA_BINARY }, diff --git a/net/ethtool/bitset.h b/net/ethtool/bitset.h index b8247e34109d..b849f9d19676 100644 --- a/net/ethtool/bitset.h +++ b/net/ethtool/bitset.h @@ -3,6 +3,8 @@ #ifndef _NET_ETHTOOL_BITSET_H #define _NET_ETHTOOL_BITSET_H +#define ETHNL_MAX_BITSET_SIZE S16_MAX + typedef const char (*const ethnl_string_array_t)[ETH_GSTRING_LEN]; int ethnl_bitset_is_compact(const struct nlattr *bitset, bool *compact); -- 2.25.1