Received: by 2002:ab2:855:0:b0:1ef:b27b:cc29 with SMTP id 21csp1722312lqy; Fri, 29 Mar 2024 06:50:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTmD40iyfjnFpMA6ceSLtLZQ6SsUXxvUU+yiHZChN1+NpRvfyvU2+5WF6Z3dFg/UJSE71LAIRAsiBf+tg24Wt0D8DL+VztHwivzgOsXQ== X-Google-Smtp-Source: AGHT+IEHkj+4LmjpW8CVqD5gkzE6jFlFAzf+TmtKsUf134RFDNjRlCWq99JcCbT/9RH3QSb3DLFY X-Received: by 2002:a05:6e02:350c:b0:368:bcc0:a3e0 with SMTP id bu12-20020a056e02350c00b00368bcc0a3e0mr2396366ilb.4.1711720217535; Fri, 29 Mar 2024 06:50:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720217; cv=pass; d=google.com; s=arc-20160816; b=I9WSTFC0b9y9ZYDbUohiH7b0pPbOJdl7u0OZn2/dk3Umect+CXiLFrkrfIIGdPHruC LcXULDysrSfXFCYZ0rM4+1KjkzjUkDNihnbXYCBCZGwq6QMvNJaEY00QqEzMCVSrmqU5 KDUTO3d9PIaruHx6mjwHWpomkw2lRBNdrkaYTOCxe3sDWSnnd61jyB9rdftZbUYQ1843 1HEtKOyBGbuDHbDH4oyaMUN4lnq4n8rGzK+Um59fOnGPzeNgThZMJ7ZCBWpzS0Pf5Hu7 pvxwsLn/L/tZMxGSE6Z5ML7RfWqW6JTJZIgaCnJrMJ0EX4bDBR2W2wOHCI7W5W1ksCa/ NzDg== 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=LLKdFCztrJ5gEV1/97B3ADdRRxEb9WCUmXgS+SEhiE4TeGnCVcBKKco/vMRi3bYajT cANkPat4JlihY2Jo4qh+PSgkc+6FQ2OpS5owrMlrAveEIqW3djCAag01NETux6SrN+tB GMfMtjKTquRlNhuU9hSbbUZUlctgB353ih6FVI2N7Rv9UjpQ29IiTlJXiVSsliULCiQ4 gpCD4p5oB7L27EQv4qI6kTs05GJHvcgGNQUfcwGq96e7GlnsoqMW8eme4IRPKd+mTWv6 f8AXmcf+OSIUSzIu79claz+caKLtX0w+TT2ZX1FmBPKg4kgCv8RrunXGPxqgbOAWOnmA V1gA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SbJdQhVK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124764-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124764-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g10-20020a63f40a000000b005ce7efd2eb5si3548623pgi.266.2024.03.29.06.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124764-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SbJdQhVK; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124764-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124764-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 04E4728B508 for ; Fri, 29 Mar 2024 13:45:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3249181461; Fri, 29 Mar 2024 12:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SbJdQhVK" 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 0D464181338; Fri, 29 Mar 2024 12:41:43 +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=1711716103; cv=none; b=fu60G3LB/dgCDwggaL+pn7wgk4j9oOSoccpYmleWcUjSiQKuSsXyETPg7Hk6CSTyfsbE4JaTM0ycIYcQMMOeXGYoBAcCxXSbgnjqQiYzfcK73J3JlkKkpt6NA/jCLkLdKZWxqjLZaJLEcjB0tqGDpmTrfN7wt5E8sXe+rzPxRac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716103; c=relaxed/simple; bh=tPEViQjo1qr7FojiB4E3SuTTfzc9SXQ7WNdOd9cbvoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HTqxU3T53mW+J8SnNRxgHWJwpEVkFFCTvNnT3rRV8RYsZUI7Vk9eyLX5JgRKFewkvN+EvdKFGT8DJ1HJG6YhR5vS4EMrP46WkKQvoc+BDkXj17dejRJSIifCQnaglxzGxOpKSZEfQ+gny3dtf7unkF15vckJ70B9wuDiAWdaYGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SbJdQhVK; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 397B5C43399; Fri, 29 Mar 2024 12:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716102; bh=tPEViQjo1qr7FojiB4E3SuTTfzc9SXQ7WNdOd9cbvoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SbJdQhVKoCwSoDC2GrvNs2ukVT1NQ6SkXgVnY5RGzE/yMmyLlordTj9oWiKiyZS1G PKQ6bUeICyzINAhG7dUvWgPN2bhTCaKqarDxUuBRixhIA/ubMAeWtHuojZLUXra9fk dnGYXUk3pEtjUxVrgUu3GMDHGljYy6bBtq/StKuaC5GHgTwW4DfBS5P/uRSM4LJtPG Y92FlGUrudb195X6oAVDL64CA4Z/wans0AYbfNtPRq9SKJ2HJmAjuV0YzmqBQtuqtQ B1azTWoWqtDDe1NoR8w0lubyeKro/tJxcGqdf3+3WOKDlEOCpHCy1tRCCTRXYnzcuT DtXMR7DbZBjvA== 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.8 55/98] pstore/zone: Add a null pointer check to the psz_kmsg_read Date: Fri, 29 Mar 2024 08:37:26 -0400 Message-ID: <20240329123919.3087149-55-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 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