From nobody Sun Feb 8 12:14:48 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 1870520DD53 for ; Fri, 10 Jan 2025 12:57:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513844; cv=none; b=jWt6IyzFWQfluEpXMCwuPbIb8FuaZNRryEvTDxYuSJJrC6hPCOJmLa9xaHeapbcix8dPy9wpBPOyAVYbK2Llk/oL4YanYWlSdZuT0jV8HzJkXv4ganzQWDz0lrIv7KwNT5bmJG5K7k8IYufJSwII/oKfzcmgMuc5PG7eWCce05g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513844; c=relaxed/simple; bh=O7s4+YeAaeOezbUQ0uUAF3HuaRoXn0zbYMHRN4K94VA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oBvLNptlZDOI6iPnvafM262qJlLlOz1TmQkpXqfaD73ot8wRki/m8SBt1jxEfZGjdfRo1b7S9QbKZXxSnXZ8ooz8gBHw4i8brqZFScn5iy+nd1qUSUeBfkFll62IRJRLN/Z3rMWowJEYWCKWDBq7c0n0AclXwqm0Md0x+7TYO7c= 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=UkKQlMQB; arc=none smtp.client-ip=209.85.128.53 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="UkKQlMQB" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4361e89b6daso15302625e9.3 for ; Fri, 10 Jan 2025 04:57:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736513841; x=1737118641; 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=JuO/PfXVbd8eOsHL6xLYlrc5CHMwEpP9FRyOGs7V7z0=; b=UkKQlMQBprwPiUHiXM8r9Q16K05oJlM4GRY1hZjF/gbZfhkubsyXL7rZFL1DbhYmo3 2C/9n0D2KTzqkUMmjDLpmZAoux12gZUWsDY0v00PPSKC56eaAhW5BDNJl2othY/1odoo qQG6d/t6bqQ2FifpJlo2tE1rRGoZn8QxmoaqmuYWyCJexP/nI1sovhaXT6J2xTZEIh4c PYwgyNZ0wGk7kJQeU1/BofJPgUQ+p9d+QRF9mRzLEmXzE9oVbqxzsN51Pubm4IBPbTRm mkVELCeFAzx2uo4xxBlFLIJ0XEOkJWaRXV42EnN4PveFx6MkcJbse4rB95Wk/T5Ud7z5 QgSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736513841; x=1737118641; 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=JuO/PfXVbd8eOsHL6xLYlrc5CHMwEpP9FRyOGs7V7z0=; b=oIuM/RQJcyBjDXOmSnPfrpoGoDcsXCOxexM0S37vHn3Jbu1plNH9H006pQp8Ek8rBR 5rX5pC2D437jC3CtrWWW4ZbTyws9ZIVYrCFMtcjmtqlXuX1VWNuzNG8owk5uxK8zY6LK p8Wrjhyemn5dYPt0gwmpgypmf0z7P+0Gv0yL+7jjMVmV2y+ZIgVWYJKA1IXayK6ai8GD uRmthYLu5p+uR0CvcBgWL1aiP7UUfsEfbKNVzrcj77hfhSSOV4IozvpAmWyq/ms7dr7y 0F0DtVfGx57DlRwVk95+3mRSiRqs/Kvn7Vzxb+pmcs9Nu7yPeb3JFCRV1GSGkc6aaqdm thvQ== X-Forwarded-Encrypted: i=1; AJvYcCVSiXgsi4uwkQrQCmR2rmm50qThgGX0j5hZ0sYMpEbrPePHzT+R1FY4facQIPlmpHUj+m1B5Y/MAzoJsQY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0SQFl6UHhE/ZEfpNw92sk1RtSMXX6QQkRZZ8j1jDZTnY8t425 J7LOoA1IOyE60T5CYfoUJ3+3S1xHReXtFsjXfl1vvraHaPQI+G8bPQQNkVIkpno= X-Gm-Gg: ASbGnctffKm1VXw77Gv2MjXqyGPGp+KggOjM0XMS29H58gsInwmdWGDCLrMa8Nm+rfO eC3gD0cJY1FIObw01mIMgHbwFFL0HCfUJ2ktSxSJwhY5kDszV9esc37Cd7reOugor/z1l7YEJHG k3w8YY8bJqFFCoiSnkq1c2anTcToZeXXmYjaCLuwjZsMnIBoroSRNEpCieuw8jZ1q55QZKv2+gc akyi5MkmoO7R0DUFyQmjcasMJjp3rQQuun2I1leepUSIQslCuv+E8ef1n1Mwmv2wnI= X-Google-Smtp-Source: AGHT+IF1ZIPyhPMIsBOrLkPqMM0CspLLHLyCMAkP93UYVxdRI64cHbeoj+KnpGweyYlZfjm5rQo/Ww== X-Received: by 2002:a05:600c:a09:b0:434:f1e9:afb3 with SMTP id 5b1f17b1804b1-436e267863emr91888235e9.3.1736513841515; Fri, 10 Jan 2025 04:57:21 -0800 (PST) Received: from eugen-station.. ([91.75.105.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2ddcb5bsm87602755e9.23.2025.01.10.04.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 04:57:20 -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 v2] pstore/zone: avoid dereferencing zero sized ptr after init zones Date: Fri, 10 Jan 2025 14:57:14 +0200 Message-ID: <20250110125714.2594719-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 --- Changes in v2: - reworked to check for c=3D=3D0 instead of ZERO_SIZE_PTR as suggested by K= ees Cook fs/pstore/zone.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c index 694db616663f..ceb5639a0629 100644 --- a/fs/pstore/zone.c +++ b/fs/pstore/zone.c @@ -1212,6 +1212,11 @@ static struct pstore_zone **psz_init_zones(enum psto= re_type_id type, } =20 c =3D total_size / record_size; + if (unlikely(!c)) { + pr_err("zone %s total_size too small\n", name); + return ERR_PTR(-EINVAL); + } + zones =3D kcalloc(c, sizeof(*zones), GFP_KERNEL); if (!zones) { pr_err("allocate for zones %s failed\n", name); --=20 2.43.0