Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp32078lqz; Fri, 29 Mar 2024 07:43:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW0LxFLJolIWwQFLr12jFPFfmhfTfiYH8h3P/7J9/RRDQtO5xr6KocDkTe/EtCWSH4NceqZGKF+D3gUr2kIJEGTF9p4QMz0tuClvOVf8A== X-Google-Smtp-Source: AGHT+IGbotUK8Td0djTrAjj2rxRbLOJYUwkzDFGmkU0uoJ6Ob/ZuDkIajtv/cibqQuYogG737+nw X-Received: by 2002:a17:906:aa4a:b0:a4a:391c:7feb with SMTP id kn10-20020a170906aa4a00b00a4a391c7febmr1601449ejb.20.1711723422069; Fri, 29 Mar 2024 07:43:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711723422; cv=pass; d=google.com; s=arc-20160816; b=m8mgp8+DkjS9SS7OuxWm3UItK1L2I4uqrmADQgxxHtu3B8tev7uy6CCOFKHI+GFr1X IIpV6w0JsLFJY4ox/2TZDuzxG9V0i2szTSp6ZiAMpT6ovTOlNVbawLa/oKhQXA39J6ZA vKoZJZfdDLJuDMHf0kwexJu0AhndL9rScm2XpXx0g6l4rWeAtlpK9MninqxNQiYXDXaE CdvA03P1g/CZfWi/PkVG5CaNWLt/4A18ksTPJ3NnepXSXwH1F0o08jPCZXWt4w0iY0IZ Jv0/Kkmu0AKEsBoo2Cbi6ng8oFEZ0mTb/Mvmq5emztIswgsGBJZRWcF6N1L5K7VKy/Vp XryA== 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=689Kd2m0syyV2Ffj2Vxa11zwH+HQfZZhpW2x++xOkGE=; fh=0pPTAxgwdAh++uUUIIs48qcsx0W1gw+0G9L9wxOeBOo=; b=TOKMYfxwXh4CFbOAFQYS/8n/qB6ZMXwjMA6MTSbGUNrjH0K5331PcxWWHwnDThfTGA nb4lXrZalns8RO9KXb6gw+AgdMfmAMTAOFaP27MbNiilSC8yF37od9u8sF4e7jdv54DE ZD2s3qKy2/NpvNIXPxG/eqiU6up7ZNt36eJzuYV9Eg8AlvbmN/rtqB8YnQnpaXPH+Qni 3KCGN6KHpj8XB0qGvCpNr8hlwl9qVttTE9thiAG8qLDj7jnprhbmcvD7+e2f+tiEv5jP p/EfCdcjwXeYvjWSbW6Qd8bklSCUBPpyJrkInqie2kdvzPUzsnpRkx6JFPU7eFzEbPTs bvaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GJw5rFhb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124909-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124909-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 f14-20020a1709062c4e00b00a471f96d59asi1852553ejh.674.2024.03.29.07.43.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:43:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124909-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=GJw5rFhb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124909-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124909-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 C18AE1F2A934 for ; Fri, 29 Mar 2024 14:24:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8563E29D3AC; Fri, 29 Mar 2024 12:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GJw5rFhb" 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 A26EA29D398; Fri, 29 Mar 2024 12:46:52 +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=1711716412; cv=none; b=WaDrt+UN58z0fa3g4Td6k2+MDN1Ko8dydKYqBoo+KHkicMbHI+9O41HCzBRIdNwWONJJiHoXpbaeoBc+z3M1HyVMbBBqJ9wFaPFwI954fFKXNuZdmabvA8NLbIQuus6S3Zm9GmsxljuL3Pse3yIepG4thRC5uX+SEO1vJeEkf5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716412; c=relaxed/simple; bh=tPEViQjo1qr7FojiB4E3SuTTfzc9SXQ7WNdOd9cbvoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ejyOarLIoEzi/h0F/bpfqRo4IJjVo1wRpKqzzzpK0SrdIWI5bRbeNUyn5sxZoI1zt0mqcjM92YY3IGnbLlMV63Wzg44pI8dy9kPLSUtqRmgwGD21S21M6XNKIY+UtaqDGCmojcOxa0spmyL0SL3BEmLS5QmGgpngz7V6aSodu38= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GJw5rFhb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 631A9C433B1; Fri, 29 Mar 2024 12:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716412; bh=tPEViQjo1qr7FojiB4E3SuTTfzc9SXQ7WNdOd9cbvoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GJw5rFhbh9Ucm8SMOvpvnc9dN5ggPWhsodYtPbKtahGDKrqYLgV1hAhGaStPljgwK 20tzKKu7yiCKtrKxtEtPUhG7pfH7RyICt2jXG+Q1jXfsyfiIPZeap9ms56VVnch3wu /TqhMARIkR8Q0O79tFUc/3b/WpJRSIOue4tJmh6x2RW2voyygV5c5UQNy3Q0tgVpgq GZ2KdNleIOGd6y6s8d49Sl3Uptaw7+YQrrf0Rlk2OSnZs2J2mq6YWbnMo0q9iMrmCc ySuBX6BmVw0xKSN4qBwzAZANRgHRn0ZHYlQPlcsPs2T55imD0Q3rSEVPVEmdwNdWvI E/j1HoHbKPeMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kunwu Chan , Kees Cook , Sasha Levin , linux-hardening@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 25/52] pstore/zone: Add a null pointer check to the psz_kmsg_read Date: Fri, 29 Mar 2024 08:45:19 -0400 Message-ID: <20240329124605.3091273-25-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-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 6.1.83 Content-Transfer-Encoding: 8bit From: Kunwu Chan [ Upstream commit 98bc7e26e14fbb26a6abf97603d59532475e97f8 ] 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 Link: https://lore.kernel.org/r/20240118100206.213928-1-chentao@kylinos.cn Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/pstore/zone.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c index 2770746bb7aa1..abca117725c81 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 = kasprintf(GFP_KERNEL, "%s: Total %d times\n", kmsg_dump_reason_str(record->reason), record->count); + if (!buf) + return -ENOMEM; hlen = strlen(buf); record->buf = krealloc(buf, hlen + size, GFP_KERNEL); if (!record->buf) { -- 2.43.0