Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3864323pxv; Mon, 28 Jun 2021 15:05:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVzKTzfXpPqj8rIo/qFpxdOEazfThzrtxwOgvd96UYP4bkNi+6gytyZJo/EDIsvEfF2Kz6 X-Received: by 2002:a05:6402:204:: with SMTP id t4mr35488417edv.34.1624917915770; Mon, 28 Jun 2021 15:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624917915; cv=none; d=google.com; s=arc-20160816; b=U5tjFlK9rdpe212ldr3glm6jlc6O5MktoOHZpGRVeZQawEeWNLIvs1TfbC1A/eVSmw IycXwAd//4PM9u8kXnidTmfrVhsvgOWC1P29byutVaJMgurI5jeOCxtw8NreW7ik9u12 JNrSzaO2cwu8gm/qcLzJaMK627UEVGYDj+fd2KtJRaPMn3zxb1wLW+L0HcreLbiLPX5S i1EdQFqDB83UQLKraQuOX9XoW6ag2Im4KAcFD9CYE4WCMN7PPiTFcR175c/hG6TsazCp qUD3yY3j/Wyfsi4t1yuxByqq1cu2l7DtyqKdr5Qt3VMR/eqCLvienqDMuzfjUa53Ch/P aIxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X1ylFDqwxIlezY0fGb4vjsa8vqHnq7oDXLX7dAaRKkY=; b=q1voCq5gVkrZyTscGjEWSiChKvNG0PoNBgsCOLkXux3/DyMGtZ5dUCrBEBdzHIwvis VY98GuHZ3RU2N2HQQAgvTotbt4kbflL7+S60Jc6g9LoWKXpUYhp8venVt183cAPR2zNM NTOadJyI9krMHxVUSmn/tG93rP5/bm6KdMlqpKIyqC3OHwr6gTaE0syE+LEC3PiJY16X H7p+VXQJ7pb3qXeLyh6mhcRRE8ulCz7MVNye+nwUJUh065hTcoLhjAjuH8maNYTFecP+ auHpcEHpV1h3rFOECbg+KYEGjZGP3buuRXuUYQ8sZZx8NpictbaHSuSqUuTz1VL0oELv /rfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SYA3k9gp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si1192733edf.277.2021.06.28.15.04.51; Mon, 28 Jun 2021 15:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SYA3k9gp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237064AbhF1PZw (ORCPT + 99 others); Mon, 28 Jun 2021 11:25:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:37106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236172AbhF1PCN (ORCPT ); Mon, 28 Jun 2021 11:02:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 359CF61D7C; Mon, 28 Jun 2021 14:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891262; bh=k5qbGDjrmYPjqZwRGbFcF5nge5fMT5E8R3/0InNUKos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYA3k9gp/0XmhJntHEKDzuRrw/qg5ZQFzIhy50PJshB9P8aeYeBJBGWAaIQ/YoM7M hLFtkGwmid1JeVl+PxqnxSPLLH0fdV1z4QYIENgu7f24AgirC3+ducK++bEO7jXY02 u93QUM2auV1LzneaBFPzx6aLoEYQ03jVVnLhZOMkRlgVwURoF8fX675rrWKrXWsKha TKmZR548Ow31zmAxmN28NfKNBV1ZswGLeD1+Eb3Yt7EiIDrlXBtX7zIE65GigRl8Jd KqyZiF5Eqwce79+rr4IzcSSQ9YhNJNIHXBhxLJbmVsg4dTm7qwYcgAqIdGZqzNPB+f cxIXF3g2Sa09A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , "David S . Miller" , Sasha Levin Subject: [PATCH 4.9 67/71] net: qed: Fix memcpy() overflow of qed_dcbx_params() Date: Mon, 28 Jun 2021 10:39:59 -0400 Message-Id: <20210628144003.34260-68-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit 1c200f832e14420fa770193f9871f4ce2df00d07 ] The source (&dcbx_info->operational.params) and dest (&p_hwfn->p_dcbx_info->set.config.params) are both struct qed_dcbx_params (560 bytes), not struct qed_dcbx_admin_params (564 bytes), which is used as the memcpy() size. However it seems that struct qed_dcbx_operational_params (dcbx_info->operational)'s layout matches struct qed_dcbx_admin_params (p_hwfn->p_dcbx_info->set.config)'s 4 byte difference (3 padding, 1 byte for "valid"). On the assumption that the size is wrong (rather than the source structure type), adjust the memcpy() size argument to be 4 bytes smaller and add a BUILD_BUG_ON() to validate any changes to the structure sizes. Signed-off-by: Kees Cook Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/qlogic/qed/qed_dcbx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c index 7b6824e560d2..59e59878a3a7 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c +++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c @@ -1205,9 +1205,11 @@ int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn, p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE; p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled; + BUILD_BUG_ON(sizeof(dcbx_info->operational.params) != + sizeof(p_hwfn->p_dcbx_info->set.config.params)); memcpy(&p_hwfn->p_dcbx_info->set.config.params, &dcbx_info->operational.params, - sizeof(struct qed_dcbx_admin_params)); + sizeof(p_hwfn->p_dcbx_info->set.config.params)); p_hwfn->p_dcbx_info->set.config.valid = true; memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set)); -- 2.30.2