From mboxrd@z Thu Jan 1 00:00:00 1970 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 CDD6A226554; Sun, 26 Jan 2025 15:04:29 +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=1737903869; cv=none; b=YmCEtjucgxsX2mK+ncvtqVEPo7X5icvj7lzCG0RBWQG7wEZcT4G4G8T2FhgQE+jGtE316aDU2VvLxc9DKl5S6wYi2kQH5V0n878ko/urcfFH5oS3p9N5YBhzF/1d5HxiHsVjGpZcCATzRcW1q2ygM2VR39aXi3fJlheaZI24Q6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737903869; c=relaxed/simple; bh=ziFWZv+l/3BL/VrP9RAmntpbE18Jp94WGFFTvvMVeuU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d6N8Gs6msy4BLUDbdSBUA5mujoR5vViCmUzHw2SKrlXEC1sVJSqwAuE8RUX/f99buwBKjB7VqhXG2y4TO0pWB1sX2lkMOXktJJ0wfRNaEKrLXUd3VbIcRJ4vVElau2zsA1wSugbj/U/UvJ10vjap405C+Trshkgfb0QQwrdGZ1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QUASVhHB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QUASVhHB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59B40C4CEE4; Sun, 26 Jan 2025 15:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737903869; bh=ziFWZv+l/3BL/VrP9RAmntpbE18Jp94WGFFTvvMVeuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QUASVhHBRgSfpjMs3A2FjeLMCj5VUq4xRlp/fSe73/3+5Uv2me6b8L67ZjJitGUQq BNpp6dG8LXSYax3BeqYqjeA2h1+f+5XX/L3ohY+81uU2zjm0eURL+mzQyOaVEOR3NT 5oQyJ9zarTCja7tq0DhTHYYGLgleKJKLZ5Gfkwp/QziV9bxnyriwRpXKIvOWqCsVEA eBbe2fsdFFuHfULh5JBni1fBCBpY4eZAi4gI9S2e7cxS+sVFkm1k8nzEwctEfPDD3+ dj4NeSymI5iIyErBrskW6lHjAGiCPXu7egNszRQ7gOXgDZm+jJ/FJmJ8e24OGjCCdu +hN31szham9EQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Liu Ye , Jakub Kicinski , Sasha Levin , steffen.klassert@secunet.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 17/17] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Date: Sun, 26 Jan 2025 10:03:53 -0500 Message-Id: <20250126150353.957794-17-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250126150353.957794-1-sashal@kernel.org> References: <20250126150353.957794-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.127 Content-Transfer-Encoding: 8bit From: Liu Ye [ Upstream commit 3a0b7fa095212b51ed63892540c4f249991a2d74 ] Address Null pointer dereference / undefined behavior in rtattr_pack (note that size is 0 in the bad case). Flagged by cppcheck as: tools/testing/selftests/net/ipsec.c:230:25: warning: Possible null pointer dereference: payload [nullPointer] memcpy(RTA_DATA(attr), payload, size); ^ tools/testing/selftests/net/ipsec.c:1618:54: note: Calling function 'rtattr_pack', 4th argument 'NULL' value is 0 if (rtattr_pack(&req.nh, sizeof(req), XFRMA_IF_ID, NULL, 0)) { ^ tools/testing/selftests/net/ipsec.c:230:25: note: Null pointer dereference memcpy(RTA_DATA(attr), payload, size); ^ Signed-off-by: Liu Ye Link: https://patch.msgid.link/20250116013037.29470-1-liuye@kylinos.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- tools/testing/selftests/net/ipsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c index be4a30a0d02ae..9b44a091802cb 100644 --- a/tools/testing/selftests/net/ipsec.c +++ b/tools/testing/selftests/net/ipsec.c @@ -227,7 +227,8 @@ static int rtattr_pack(struct nlmsghdr *nh, size_t req_sz, attr->rta_len = RTA_LENGTH(size); attr->rta_type = rta_type; - memcpy(RTA_DATA(attr), payload, size); + if (payload) + memcpy(RTA_DATA(attr), payload, size); return 0; } -- 2.39.5