Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp240983rdb; Thu, 18 Jan 2024 02:02:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1i1OZRfvRNUmbnOnUIrXPE02Iud+1DmqQkIlBXi3HV/iicvdO+gKmVAvbP2Lwhel4jRx4 X-Received: by 2002:ac8:5749:0:b0:42a:1132:6531 with SMTP id 9-20020ac85749000000b0042a11326531mr873075qtx.50.1705572148194; Thu, 18 Jan 2024 02:02:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705572148; cv=pass; d=google.com; s=arc-20160816; b=0sWLqSwZicoAX6IRmZJgN7iW95HGrLT39yEcoOplYHi4cNlYXBsTHrS26zaGkh+ByJ EjytaVnVS2FI+S5nGkIWJzpPj+Vb1FygXDxK2x0tiF9PL8HCXFzW6oClziMmYv2FVVWj RRI7/1NaZ3H/x708fHQixIgMWQOx8XDFgQABDqYYNagtF7SJkn7lOIpfpJ79YVh/0VKH xKhODbr1EF39KKcJd38msTmkezEqXSdHAVjU2kjgstzBfyLg8SGJZVT91CT4Mi3sc291 QdmyuEsF5ZUwwJVzF2/IanlIrzwL/gTHz+7DwhrMUHabYbZNu6wvramoeiM1XzqlUNby DYiw== 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:message-id:date:subject:cc:to :from; bh=2dm8B1fBj7xZ5dxE22Vlj/DO1oHpcUJLfPWtFpjjy1E=; fh=AosG85scXsuqiKfsOd7zNjA5KdmyZtcKowvyA2bvPBI=; b=rh35339l5MJbbBKvATjs8EEbUdqmbreuQWpcMqSlhNPTtTJrj8qMCTDaV+EFxfkXCZ xAi13Eo/h1RaCaT5lBDWOI0zsBd5GCF9HfpqwBieh3vfDzmvog7ugjbgFldHLo+qMapT cpekqXxsoXDEhM7izNWSwlDpk6Yi0iH9y7fSlAuoeUfJV7FCEjZmpXOsCevUrBQOazcK rXP4lMpV77N+VLf9bj6lRY/PmVDjUnW9VMmt7Jsdwh6aQvVZu/gfPjMQF4xSIUvVtFH3 ChuYGNUDbIIGnwuGyIsdTg6nqJMGZROj68R5UNKf0R4IwkuisFb7ttl+miSC2xVxegOm 7VZA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-29992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29992-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h15-20020ac85e0f000000b0042a12dd4961si2318825qtx.281.2024.01.18.02.02.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 02:02:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-29992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29992-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EEB8D1C21805 for ; Thu, 18 Jan 2024 10:02:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F7BC2031B; Thu, 18 Jan 2024 10:02:24 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 9807320B0B; Thu, 18 Jan 2024 10:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705572144; cv=none; b=DoaElumEAyowmwYhDNkPblPtwCLCxfhjzKGZDSb5axC2aHvl1OCgaWXTJTS3SfShYOPMxbo6kx3XQSLaSIr6ckxWF5Lm267L1iYpjr/i/faK0VjfiMgF+DtoGR+QGwVBr6D4Myjhp0C4+Udpt944WWpIyidBLjKDp5EW5if4Y2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705572144; c=relaxed/simple; bh=OB9o0jiUtNKehJapIrC/Pp6m/oKy2ANatHpFJ/5DvbM=; h=X-UUID:X-CID-P-RULE:X-CID-O-INFO:X-CID-INFO:X-CID-META:X-CID-BVR: X-CID-BAS:X-CID-FACTOR:X-UUID:Received:Received:X-ns-mid:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; b=Nq1+ivXPbDvbp3jM1d94pANy2nw6SfmtjfF0AITUo1rr8Z2P+yZ28kHVAj6Lta9dWxuHjyEGkhzqmX2xIK46rHU85XmjZrA6jpq2HQJw0k4K2rsymecLBQrYZvVUBrfcyrfzmel2idYnZJ6rlPdHzoS6UyuoCoUkYcUaH68KxhE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 4d6849fc017b4a24b9e2b5ba77e007b3-20240118 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:1010ab24-0c46-46a6-a1be-87945ca9a23a,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.35,REQID:1010ab24-0c46-46a6-a1be-87945ca9a23a,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5d391d7,CLOUDID:63797d7f-4f93-4875-95e7-8c66ea833d57,B ulkID:240118180212MAVKV8H4,BulkQuantity:0,Recheck:0,SF:38|24|17|19|44|66|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-UUID: 4d6849fc017b4a24b9e2b5ba77e007b3-20240118 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 742518887; Thu, 18 Jan 2024 18:02:10 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id C0AA2E000EB9; Thu, 18 Jan 2024 18:02:09 +0800 (CST) X-ns-mid: postfix-65A8F721-215790310 Received: from kernel.. (unknown [172.20.15.234]) by mail.kylinos.cn (NSMail) with ESMTPA id 3D926E000EB9; Thu, 18 Jan 2024 18:02:07 +0800 (CST) From: Kunwu Chan To: keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH] pstore/zone: Add a null pointer check to the psz_kmsg_read Date: Thu, 18 Jan 2024 18:02:06 +0800 Message-Id: <20240118100206.213928-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Signed-off-by: Kunwu Chan --- fs/pstore/zone.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c index 2770746bb7aa..abca117725c8 100644 --- a/fs/pstore/zone.c +++ b/fs/pstore/zone.c @@ -973,6 +973,8 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone= , char *buf =3D kasprintf(GFP_KERNEL, "%s: Total %d times\n", kmsg_dump_reason_str(record->reason), record->count); + if (!buf) + return -ENOMEM; hlen =3D strlen(buf); record->buf =3D krealloc(buf, hlen + size, GFP_KERNEL); if (!record->buf) { --=20 2.39.2