Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2096922lqb; Mon, 27 May 2024 07:47:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUisdWWi3tyyhdHbGLTIPx1ImksfEQINEKYcJVr/dkHwhjoXdSX8oFiBW3dlIXsaRBQm9QBS7pNmFWsar0Ee1151D8C40Y5W2nMhqLe7Q== X-Google-Smtp-Source: AGHT+IF1Kn+yZVQmaY5ifnXV5xYm5BJw6Vor8yL6UyumztvCTKDveC22iKC0PeOiQG7tlwL59gRv X-Received: by 2002:a17:907:9451:b0:a62:cf3b:77af with SMTP id a640c23a62f3a-a62cf3b798emr397448066b.52.1716821265488; Mon, 27 May 2024 07:47:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716821265; cv=pass; d=google.com; s=arc-20160816; b=DccveQpqDeFsGk18WFjg+jGXmDXqzSmVkxcRfRKmQJ/zWYbXdeOiVhks0TbGj7q83U 8D/IXHr76pQ8+3lSCgU4lJDu/0u9BVHypflhkM/24ciLDnLi2YvYZaAg6I/dC8zpmXgY h/8bDKvfjwm3brYkjYylXuCNEiwQJ8MWF0ibdKCm4rK2a9ovXXhTrNbuJOwUsBxhpQ8H wvic87IljQM25TyO0DgGY6PpQvIyb2QYrVTqDh6rAHu8MKNUJfUOR6ssBG4juKGYXAtE Wr+Cl9aueIvYiUOJ4rB51moE9urrueKHI9RqT+MY7sY3uScRRjYCQk6xr99O4Tx7WAFo 3KfA== ARC-Message-Signature: i=2; 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:message-id :date:subject:cc:to:from:dkim-signature; bh=/P4kYk/4rUxssps/f9nd00szdhqzjogrbRIkP4xMVig=; fh=Z3y/G4pVtxPbECZUBEmikqsEpGRALPnGlNOOg8IKdqQ=; b=VPMYhH4YVhrFxSBE6pQ/Q+cVC6WQnPbwNjpbpXKJT1GrtVr8gDUnFCb3D8ZDVeURd1 vzSZzLBphRtjRHN9sIQYIKpHe9l1u5RC6jMONSmCy3q1240rfyWGNpwT2rsKwLoSvcjK AsTv/CQAxtZBt8dnNiIVMM3eUcT6lVHC0O3MxNIzfwPtPi+hXj9j8hLVOlftS8IW+sEm ShU4StqNKnSvKJd8HTlXMOsv9Sp8mdux1J9Qw1ByscvsCEZL2uh4poJAcFjZnzl6z3Uy RWpfgcQlzHlivhdrB8jUsHwxHJpdcgqotySft8WDEiINR6E8A0z0fNNrAu3jgXlcUdH4 ykDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C2Lh37GA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a62c263578asi229551566b.819.2024.05.27.07.47.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C2Lh37GA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-190929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 13AD41F214E2 for ; Mon, 27 May 2024 14:47:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38B8916726B; Mon, 27 May 2024 14:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C2Lh37GA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5E94115FA6C; Mon, 27 May 2024 14:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819564; cv=none; b=basrUdTQhcFA2ZM6BIJCYSU7K43gQn/685Bz3Ul6tMEruEC/axaVRosC8sJy8AcvveRPbDNTrlMaKAh08CplECivrFhYC/xfuzE4A0eT9vddMWhkLu7q9Rcrp2gp8G9J2kD84hhJl5hgd/khucg/2Fpt49tBBx5tFUtemFtU4jk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819564; c=relaxed/simple; bh=Z2Lu6fp7hgS+t8UgQUG2yU3FkRiF5IM8aE8wjUPcwZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LkOmnffcMQtwpa9u9E+AGA2r/b/NQq2ZsWcpcc742wJg38Vw2h156QfhjYSj3/pnW85IgRf9SoXELJql237Isy8Qnd75dOvajexcx3c9BFNukPZi2kOWlqE+/LpQSy/F52ykVo0hnDRQBHSmfXJMcA0i3OjFjQKpzgHNIurSUB0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C2Lh37GA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EF0BC32781; Mon, 27 May 2024 14:19:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716819563; bh=Z2Lu6fp7hgS+t8UgQUG2yU3FkRiF5IM8aE8wjUPcwZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C2Lh37GAeVQg5A0qg19GVfleMzdSkEsmV1FQtX7c8lTemcwwwCFyhMT9xgA0IizZX uJoesFPPf6joaMYRAwX1dmmmrM3DHPla8tFuBs8/nKvqkeWgxiVoMXTJpmLQyOZOLi CI09ddBKjlcjkHZ932r9r0KeCZaZFx18TXOzkwswdDYNHwBl6L1sluwc1dGSSVZAdv o01G6MC4kQ0iYQ995xThGOLOT/sGwi/fMnjpHCVoRS8ovZ0essHjQ8+D1ILP95JSqf 4v7t/S29uaRRV2po8CwNK2M2oiFcpu6K73ivQVpD8k7NrIlO7bPEdUQ+bArzx2OKg4 icO1Xdl8TqTXw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , syzbot , Kees Cook , Willem de Bruijn , Willem de Bruijn , "David S . Miller" , Sasha Levin , kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 05/13] af_packet: avoid a false positive warning in packet_setsockopt() Date: Mon, 27 May 2024 10:18:42 -0400 Message-ID: <20240527141901.3854691-5-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527141901.3854691-1-sashal@kernel.org> References: <20240527141901.3854691-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.218 Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit 86d43e2bf93ccac88ef71cee36a23282ebd9e427 ] Although the code is correct, the following line copy_from_sockptr(&req_u.req, optval, len)); triggers this warning : memcpy: detected field-spanning write (size 28) of single field "dst" at include/linux/sockptr.h:49 (size 16) Refactor the code to be more explicit. Reported-by: syzbot Signed-off-by: Eric Dumazet Cc: Kees Cook Cc: Willem de Bruijn Reviewed-by: Kees Cook Reviewed-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/packet/af_packet.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index db5d16c5d5b11..3ae11961c9cc3 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3762,28 +3762,30 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, case PACKET_TX_RING: { union tpacket_req_u req_u; - int len; + ret = -EINVAL; lock_sock(sk); switch (po->tp_version) { case TPACKET_V1: case TPACKET_V2: - len = sizeof(req_u.req); + if (optlen < sizeof(req_u.req)) + break; + ret = copy_from_sockptr(&req_u.req, optval, + sizeof(req_u.req)) ? + -EINVAL : 0; break; case TPACKET_V3: default: - len = sizeof(req_u.req3); + if (optlen < sizeof(req_u.req3)) + break; + ret = copy_from_sockptr(&req_u.req3, optval, + sizeof(req_u.req3)) ? + -EINVAL : 0; break; } - if (optlen < len) { - ret = -EINVAL; - } else { - if (copy_from_sockptr(&req_u.req, optval, len)) - ret = -EFAULT; - else - ret = packet_set_ring(sk, &req_u, 0, - optname == PACKET_TX_RING); - } + if (!ret) + ret = packet_set_ring(sk, &req_u, 0, + optname == PACKET_TX_RING); release_sock(sk); return ret; } -- 2.43.0