Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp504997rdb; Tue, 16 Jan 2024 07:10:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuJ2J50R05uwU1WKgkiZv2c2JaEI2pKeTUXJYSApN5Z8b2r2NC02Y0cHfWfiY8eQC6F8LL X-Received: by 2002:a17:902:f684:b0:1d5:4b18:17c6 with SMTP id l4-20020a170902f68400b001d54b1817c6mr9173347plg.62.1705417834806; Tue, 16 Jan 2024 07:10:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705417834; cv=none; d=google.com; s=arc-20160816; b=LV/7gOQQFYvOKrPIawV/Qo63xzPSQ4hmQz8VV9ira7cqWX9hB5A8mVjWgxVzfSV0Bp ITBKMQ474xs1HnCgaSyx59WWFhxuM4NWOPUAabzlX5WI9RcJ8lOsoiaRIvWZ8QEmi3pP Q+mB9/Wtl2wBPfxjWhJx3wKqSKnCwmAErkY+5EN/tpSfnRX+HIpeQcfdAF1c7rweKO91 pieP71hfWOuCaath8DXmQ46OTa8iVJMZ0squpEsNc9yZPK3Zi+uF9ZBuQHUGvNLtKP33 YPC5IPFPGd83kNhBAberdFfbjTOhhfFWjxio8dEfMyAqWW1lSwN3FIRa7mxjUa36/FkK 6rXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:date :subject:cc:to:from:message-id:dkim-signature; bh=qjcLg5ms9S47F00EB6wAMEe0GkzvYo0BfBYr/994CQc=; fh=jgUX1kJSISPFHF7faM52tSDKWPiwnBm9FsfviCsDLiE=; b=GhRSThqwfcg2itkwBvT8oDdaZiDkTwbc8XVENAFptPQ6zz41v4Z+vsrppC1XkJjo1c rKMGoKVOBBl5I7ldGUmn4ht2qM8Yms1RQowI/7g3S39clzGeUna0D2+GrB4SOpwWvytt F10355R3zBsrr7MQpR1dMtwcIH9Fk3H5RJs38G8myqd9CJKr2QRjybcoN1amSSzTNY8Y H4Z4YZ29hAJwJvvSGpJ5Sqlk2sAkr6M3sqDWpsXaBN3/cI9MG5+tk4QwiH3tg8QG9SbC 2vH2TT1rELvRmFud3P/mIEYxVe1f1t40WWMD2Dv/PSiKyx1ESvcmlDBMRojbopvTySML JpqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=XXiCmNju; spf=pass (google.com: domain of linux-kernel+bounces-27501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j5-20020a170902f24500b001d5e99e9437si1288355plc.110.2024.01.16.07.10.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 07:10:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=XXiCmNju; spf=pass (google.com: domain of linux-kernel+bounces-27501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27501-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8A057B234BA for ; Tue, 16 Jan 2024 15:10:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03D2A1BF55; Tue, 16 Jan 2024 15:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="XXiCmNju" Received: from out203-205-221-240.mail.qq.com (out203-205-221-240.mail.qq.com [203.205.221.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D37B11BF40 for ; Tue, 16 Jan 2024 15:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705417795; bh=qjcLg5ms9S47F00EB6wAMEe0GkzvYo0BfBYr/994CQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XXiCmNjuospjuz4EQ3N8DN1c+80X1HHJ9G8jzzIzJKDrF/5sZo9CoH7VZHIXQnfyQ up1Z3vndEET1NwhH7jpHz2XFGyIlsH/Z0q6OZ95A55748Ee01R92BwkmBL6jD9QlbB D6JV8MBAGny3dMwX+xVorVjm34LaAfuFcSqz5fco= Received: from pek-lxu-l1.wrs.com ([111.198.225.215]) by newxmesmtplogicsvrsza7-0.qq.com (NewEsmtp) with SMTP id E1992011; Tue, 16 Jan 2024 22:56:25 +0800 X-QQ-mid: xmsmtpt1705416985taran815z Message-ID: X-QQ-XMAILINFO: Nu+mFq/+qLTW6J1GszGKKMTR/InK/Fvy2NNiFYYAucHx9hFcoWmMvR7JHZMQMf c8/RnwufjcfaXFEVBxwPWX8kFott6/6re8FQggruEDjTySyrITPffpe2xAqzthCp/eZm4Jcd4Qjd 8FeFe/rLoUx42wxdfd5WiO0mc+MvC9u1iYoczuUfLcqk+hPxNNRGaBEkgYIxBAIJma+I0ax4VG+x zKUjChCiJiCq9wbuBNj8xK6U12zYfS/IerODRuCPx4VagwfjxBDOYiNdnPD2G6jdC5UtuwM/4mZg qseaBdLpoLeJcnRPZTmLIzWnp6J77BvUom6IdX3bTsfDaifJFzOfTUKhG/SF0sTDqvpvM6k2DF6l k1KcLdiTQkzruW+1TbEP4jfq4k36MQvRL+DVnsEjPRHnurxD/+WZG7xArF20dY72JxkIRT82UYZd AYbpLaxyKEwCiAeoXB6X0jyT0hhlo1FtJ0MwgMw9x6csCZYnmlJQxooQ15a3tncLSXxYRoAWZ/S/ jTaOuIz6fS9ieuw55ITMRJf0W4O7dNbBfAwOrv3PYR4GJF7wizwFXsQkurXzhVM5PL0HZWuSp+Nh 5rVAeFpNNDhqpF2tmUZ4WvUoaDKZDuVZ/PU0U0+8vhld/0Y+L2+dMdQWo6CaKq3Ezb3VIVc1quPq bTX17yitdp8aSvbZnhhMpd6rAxCteFlJU3hV0XecdaN00fLktIA2SYAOO/jidjKIDRtq7sJehFGv BCb7Zcnzqw0+NNllbRxUw1hftKXmTNpe6pa23UXfrcQNhQt98o4l49k+TpTpKxrPZzt9F3oXVM81 Q77SSpUgeML2AQDFeqhQVJFU7UDvPp+RuUiWUo7e5ySfvws71GvTooxDKWw5rD7BB0aL+CymgUJa Y+ZVlET6B0IZ9Cl5RsHE2zfW0sXsJJkAw7w6nDy5h+/EGGvu/P2LI4jJz6kfV9dE8cEaC4Wh1zIz phRf5Hwq8= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Edward Adam Davis To: syzbot+7ec955e36bb239bd720f@syzkaller.appspotmail.com Cc: andrew@lunn.ch, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, f.fainelli@gmail.com, hkallweit1@gmail.com, kuba@kernel.org, linux-kernel@vger.kernel.org, linux@armlinux.org.uk, maxime.chevallier@bootlin.com, netdev@vger.kernel.org, olteanv@gmail.com, pabeni@redhat.com, sd@queasysnail.net, syzkaller-bugs@googlegroups.com, vladimir.oltean@nxp.com Subject: [PATCH] net/dsa: fix oob in dsa_user_prechangeupper Date: Tue, 16 Jan 2024 22:56:26 +0800 X-OQ-MSGID: <20240116145625.996134-2-eadavis@qq.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <00000000000002faa2060f02e766@google.com> References: <00000000000002faa2060f02e766@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If the private data is not allocated memory when generating an instance of struct net_device, i.e. priv_size is too small, then its corresponding private data should not be accessed. Reported-and-tested-by: syzbot+7ec955e36bb239bd720f@syzkaller.appspotmail.com Signed-off-by: Edward Adam Davis --- net/dsa/user.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/dsa/user.h b/net/dsa/user.h index 996069130bea..9a40918ee7fc 100644 --- a/net/dsa/user.h +++ b/net/dsa/user.h @@ -53,7 +53,11 @@ int dsa_user_manage_vlan_filtering(struct net_device *dev, static inline struct dsa_port *dsa_user_to_port(const struct net_device *dev) { - struct dsa_user_priv *p = netdev_priv(dev); + const struct rtnl_link_ops *ops = dev->rtnl_link_ops; + struct dsa_user_priv *p = ops->priv_size >= sizeof(*p) ? + netdev_priv(dev) : NULL; + if (!p) + return NULL; return p->dp; } -- 2.43.0