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 4D517281353; Thu, 13 Feb 2025 14:35:06 +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=1739457306; cv=none; b=pOeMsr3E29kJxiFpl5OBI0Elz4PmzfZwZFnrRU7EypgNIUvOzC3a/OcsHl1jEEdKwpDyayt6ZrpS/nTMqeSdYYAWdzrki1H71RO+icozlCdYKY1jrvUNXLaffaU2qTEzyemW3ow3BlwvlimmolHweO8z7utr6Xs7N8GA0jUnr40= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739457306; c=relaxed/simple; bh=HhIp5wbfaHL3jy3VYsakeZgXnMiV0HWSDH2Gd5nPgZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gwAASPx7EPftoNHo66pSZWNzuJ+zOG6FD5xBMRIx6yB2QBnxHLXr6FnnlZh1uzqBOXL1R2XjBfXMlhMs8SAzdZnlnqD4efpA/TnenJAs8Hk6HHxKJIbPK3vPo0h49bth5XRCShF2TEF6WbTw5ay67urELDOA93ftNCiN9wXLG1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FhYBtIC4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FhYBtIC4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF815C4CEE2; Thu, 13 Feb 2025 14:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739457306; bh=HhIp5wbfaHL3jy3VYsakeZgXnMiV0HWSDH2Gd5nPgZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FhYBtIC42PXi56xAv0Bnsi2CmaBLAmof4WO3jNL504ljyrVjA8kl6ObQ+1n8Kabrn ekibfzAnUSwDdRHONiVeugvcLxLPHr+L7BKvIJo6i+eoqrguiuiSEZNT9yashKbxIe rBwCpufaM7Hu0q+nk0tqeBdEjd6Zx1UFj+eZ1664= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Liu Ye , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12 074/422] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Date: Thu, 13 Feb 2025 15:23:43 +0100 Message-ID: <20250213142439.412261841@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142436.408121546@linuxfoundation.org> References: <20250213142436.408121546@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ 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