Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3837448pxv; Mon, 28 Jun 2021 14:17:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqHVJwM3huZBspgfsJ2amttBWyCF7LJkXAPNLErQRD2bjHwEUNUkP26R9ni4kJrlIC7sYc X-Received: by 2002:a05:6e02:1a4c:: with SMTP id u12mr19682487ilv.176.1624915042694; Mon, 28 Jun 2021 14:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624915042; cv=none; d=google.com; s=arc-20160816; b=RdxhelH/b5oc+nD2IGphUR6ixEYtDaYx4vwvDdEe+/I7pSdqafB7E307FnICer301y Sk1CADOcasKiFxAo834sX/CFmu9o8udXEJvtbgYY/KXgEQjsbLrOm8VhSKtqsxJi2EBk GqMsV0FJfwucxlK4ryy/yA76g1P+detPjiQhbLk23GA9VABwhP7yla6csU1PB8kUXsp2 G0rjkw1SuuVDRQiHE7Yyo9ppVcRQLjWw76cPYGKvQpTqeHX2Zq8eRPwo4AuysQwMebwE lVC4a00+VE0/xiXE14Oxq1x1yUWrzq8U0ACnZHu3MRAuz3nKFrjYTLcZZVUwFaEjhr6e uWKw== 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=fBD2nvGambDRauoCOHUxfdyZqJQRCrXjOX0CZ/sSykY=; b=Kjo4fVlWGrUVhzv6nSpVslQtjcTYjhJCDzjhAUMRZ9Q0zoUo9Y+1J5BN4/q0XbMOBs UdVBobb4WIh7Gr9bLpPbH8l6zpyBetWyEgHlemdnLv4I1uQsWSbSVn/bZekdzk0ir/AX vdAF4JjKW/JLKey4ZutFWBQO1IF/UB9WBW+usYn5zvw9tNIvNvwCG3rXgmMLzSef0ohQ /SvMIWPiwYDnuCov5RnPxdsEDF8NC8sdC+aY7JRp6P4vzOjHnIGUpBxNRtWpwhLdZICF Qv/Ipy54ad6sW7xSLcljmleOYUtxhDiFhEQVcP4f2m5lYEqhrXwIVfWmmV7eo6Y7MLEk gosA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TpO6LlfY; 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 r4si21983599ilb.18.2021.06.28.14.17.08; Mon, 28 Jun 2021 14:17:22 -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=TpO6LlfY; 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 S236184AbhF1PQh (ORCPT + 99 others); Mon, 28 Jun 2021 11:16:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:59764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236219AbhF1OzD (ORCPT ); Mon, 28 Jun 2021 10:55:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CDCEE61CC2; Mon, 28 Jun 2021 14:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891061; bh=0R9UgT2+08cRvY/+7No6dm4qvitd9e4Bdfrape6w/A8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TpO6LlfYsmSr87Zl30Je0q6Bi40eHdmRFwPTNbr51Zp4YnUVHN5euvVv1WukmFPtS IJYD3Jq00LxsgJqTDJlFbf5Ygk9cvBgwy7ip6gOhu1Wm6Rw72kN3eFYneyZpWbuxUy owxdHlMYjNOknez4dvYzi5xYjk0fcM0ffqaZIelfCqefmi/S/gt+8M5k/eDK9u5VSh PO+QuD3go6IP3V+jQyaqlhCocmoSz1w9NexzeyezmaKzaD6DQWDZmigSgkD/OiV9OO 9yABIFSmtCS7/rO4gfza6TbgFGAqZgb3HE0t3eAMkounEVg8Ajitzqpx+WGnAbPBtC 9p+SKDZO3Yr5g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , "David S . Miller" , Sasha Levin Subject: [PATCH 4.14 83/88] net: qed: Fix memcpy() overflow of qed_dcbx_params() Date: Mon, 28 Jun 2021 10:36:23 -0400 Message-Id: <20210628143628.33342-84-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+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 d62dccb85539..1ee58a24afe3 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c +++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c @@ -1259,9 +1259,11 @@ int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn, p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC; 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