From nobody Sun May 10 07:13:50 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F0661F192A for ; Fri, 27 Dec 2024 17:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319126; cv=none; b=Z288xKWqc78qC5rGyERZt7ZM5UBw1nOQiugbW0uA8q6nBq2pc/dWOnj8R15YVN/LySGTsNAaRbq/k8aM7SsCtAxfjh1iiKd+kpbFEcUnsTwLE4oT7rE/tW2O+dVXk6nYtBVZDqzRPQzJGF7HLc303DwPVeWFtAas/mixj78fGdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319126; c=relaxed/simple; bh=GuA0j69T1D3jsUbbW6hksH4jvBM31k0+FtA0xn79RIs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZRGcJCWx58UQM0lBw10k6k6IwethV2JK8goy7oonWteAn9pj0TiuVJpyCVyeMrvha9vjJJWspxX+333MjvyVMnFT55lxnSGnbNSgAk0iGZY3bT2ncePMwLrSXwaEkoTCAyz/achBeHZXhgXACRnhTKsiinIcslPjzN8zNbt8V3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ElvslgJ6; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ElvslgJ6" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-436345cc17bso53974395e9.0 for ; Fri, 27 Dec 2024 09:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735319123; x=1735923923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xMcLNXQnlCH4FzJqvPVgoMuXM1P9VXAukYFlxhbLbv4=; b=ElvslgJ6n+OOcn1vMYLG1hXY956ZV+MLavuC0EZwmoH4qMStj5I68A/oZbO8dZDwwY fbp1AgQZM18uCLY+fAyZ4JsZvEIfkGKfQB0T1N1CdhMCgiqpvHAARxPfR9ceScFUTY41 GATV7/fqo+378+KbXajffsQcjPDa+TNo1kBDwzNcA0bCzVFLWUAQZW9v0J49r7LEjohC Ei8Y68fFJpSScMFDE5IXdq5mivzFsDB2VYyjfcjIsQusygabEDhhvwKV54ml0mo7SjOL Dr35V1j5x8hObCFSm5hPixCmL+y+c2ShahugMezNtZGWYrsKfT/IYGlyKgEQDxENNsM5 NZUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319123; x=1735923923; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xMcLNXQnlCH4FzJqvPVgoMuXM1P9VXAukYFlxhbLbv4=; b=kc3asbxrc6LZ++L8209ObcrZHTlnAQLOd0MwRn1UtbjB54h2HkKdjvJ2rBYTg7nDvL 8LATA08WNlQlt7cGEzVGmx4z+5S1s5f0GBEwGh4hZROpi8ervyr9AS+uV/+JV/xjN63r M8X2ozWmbW06H+BxADFCIThuA7N1hkrYUmZzUm1MhD463zEyeb/zj+zHroDzrp9UKxm3 0QtbKbwvjzsv/slRiMJFRpjlYArfqy5ljPZ6kQAeKA6Wu0SfxvFB92y38h+6bStqq29C F6Q2TjrnHFYVASEAY2D/zO5sPlrkX1/qFhbsUuv0DXDRZtui2tr4vdYh3sz5HRlLTg87 Pwyw== X-Forwarded-Encrypted: i=1; AJvYcCV5YqymtQ8gwUqU+eBdXztPGGPuCm1Gq7nCXCxiD1p1Tyqe/bazN6qT+u77OmOxEjur4IriQ/vgI4Eq0D8=@vger.kernel.org X-Gm-Message-State: AOJu0YwVZHuNZQ+dhT3cmTdLvdOFeyGtXssOTNRr/ipQFinOn7RbwomW l3j1zrrhBF24Wl35KdZoARdsY5OgYsjN2xxUZj3LMlhHsqWmoYUdv5+ZV0NmS9w= X-Gm-Gg: ASbGncuFbN4cjo+3pXlsGXGXo1mXAGau/GjRJd3+o/WZj4ctl0LbuyFFOOm7vYy9KmJ MJmFMfWu+s4g8SMW0ElCBx/vedc2TKvQxZkA/joClIPP+t++NynhMirACJaYmiKBy2j/pR6KFyy XYt+V/DS2qgEyy3+76FJiqoU2kebDhxQm3sKDkcBtID2j6yf37RhSzvKCnbKqdGozL1d9TWe3/f Fitl7k5BqxhJzHqXGFamu6jo6OFiZT+b/nfHxecqD5pm9Q+0CwmuLKsUJsCHisNxsx8N1qF0gi9 OHANxUADsWXymUzgGNyi1g== X-Google-Smtp-Source: AGHT+IFDU3ZkOXqXKFiTO0JarT+esB7agCTxP4IpEOU+r30w/WDOsLDilqrQ03YgwQwyYEZl9A2yJA== X-Received: by 2002:a05:600c:3b02:b0:434:f609:1af7 with SMTP id 5b1f17b1804b1-43668547462mr226847995e9.4.1735319122787; Fri, 27 Dec 2024 09:05:22 -0800 (PST) Received: from eugen-station.. (31-15-52.netrun.cytanet.com.cy. [31.153.15.52]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366127c639sm268216695e9.31.2024.12.27.09.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:05:22 -0800 (PST) From: Eugen Hristev To: liaoweixiong@allwinnertech.com, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kees@kernel.org, gpiccoli@igalia.com, tony.luck@intel.com, Eugen Hristev Subject: [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones Date: Fri, 27 Dec 2024 19:04:59 +0200 Message-ID: <20241227170459.622630-1-eugen.hristev@linaro.org> X-Mailer: git-send-email 2.43.0 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 Content-Type: text/plain; charset="utf-8" In psz_init_zones, if the requested area has a total_size less than record_size, kcalloc will be called with c =3D=3D 0 and will return ZERO_SIZE_PTR. Further, this will lead to an oops. With this patch, in this scenario, it will look like this : [ 6.865545] pstore_zone: total size : 28672 Bytes [ 6.865547] pstore_zone: kmsg size : 65536 Bytes [ 6.865549] pstore_zone: pmsg size : 0 Bytes [ 6.865551] pstore_zone: console size : 0 Bytes [ 6.865553] pstore_zone: ftrace size : 0 Bytes [ 6.872095] pstore_zone: zone dmesg total_size too small [ 6.878234] pstore_zone: alloc zones failed Signed-off-by: Eugen Hristev --- fs/pstore/zone.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c index 694db616663f..50a765999b54 100644 --- a/fs/pstore/zone.c +++ b/fs/pstore/zone.c @@ -1217,6 +1217,10 @@ static struct pstore_zone **psz_init_zones(enum psto= re_type_id type, pr_err("allocate for zones %s failed\n", name); return ERR_PTR(-ENOMEM); } + if (unlikely(zones =3D=3D ZERO_SIZE_PTR)) { + pr_err("zone %s total_size too small\n", name); + return ERR_PTR(-EINVAL); + } =20 for (i =3D 0; i < c; i++) { zone =3D psz_init_zone(type, off, record_size); --=20 2.43.0