From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (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 5A85526B755 for ; Tue, 24 Feb 2026 22:44:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.44 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771973041; cv=pass; b=ahj6y7/2k9EqyCUBcfOF5fzBZqysB5SpxgOc5q/BDqD4hmdQRQo5VUI7WnQ8Zcrlt0iM8KJqh2rypEhiv9Rwjax7l0NGygyHAlsp9id/FI7iDD0MRzE5ShfT1adKe4Xh0+cXI8jCCgsKZavlMy/7NYwgA2oQG2+39hxAfp1psb0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771973041; c=relaxed/simple; bh=tysxSzwdUN/518teR6EyjcfeA3JpqziUCBr4+JhGLkQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=JFjPQRGJNdFilmmkWL2rO7AsgB9G9JAHTGOHJ2E2RtaEJZlH1gIW5zqwcAZ/gkCcvWpSCch6c7UBLaEIwQSvTIv4HL18cJileu9/Ltsg01T1TlfpbW2Ni6288t0Ltb2ifjb4vooeaJtrCZz2OT3xsSXrc3XQKPO4Wq+LD7Yj3x8= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1BaXKsn2; arc=pass smtp.client-ip=74.125.82.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1BaXKsn2" Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-1271257ae53so5886810c88.1 for ; Tue, 24 Feb 2026 14:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771973039; cv=none; d=google.com; s=arc-20240605; b=Z+Day/iYOVbtrOeGFr/W11KNt3XzrRPsJZOKnsTZRPR4Z0btKZtBamERiwsn0LV+UU AEwMi4McZIbi71Kw+vea5nQzEAVajQtszOEid7c2waW6jPKh2dkQhjTWZ42oiquvHWo3 F392qvhPuCm7c9EKMG0feOe1agumbKt3H/Uh9y0VYjAIcdNuPMDo/4cPcm9I6RfJ1J7v gzX8TGV/ceJbmkt2keMFXR/ZVubArzRAkhnvps7RxPljzWkqGCCckIVVLuo2oAIAfYvs dLjTGie/+EodN8RgJhsLKTlyK/oZkfdkYpXBp51eZ4Cyg3xu9xOo9LzjXL/YMJMiZd+s 78oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=0vyzXs6Nuf3YPypneYs9PIt3O29SiUmlFmPJ2dtgRHo=; fh=uP5RjV0Qpufpu+CBQ7ZN/vMD6HK5ZO9rXvuq+CsTpOA=; b=UVVrV11xBBf0zIeZNqCCDPktIJeK/sUtaIBZBZN7rgOzl7oysBB/HwZ7uUnVE3wd3J kVJFV+V1cPrXNmEVxfJb7PjIoa17ix2ojaIjT61Ba4MDQUOoQeGz+uu/pLEG/64SKHFF QrGSw06Kz0gv6rfEAliJ1UE1ztpX/BELPY/vNru7rdizuBP8UJyzMdzs0XAgh1lYSdlY syHTY4HoZyYMM8IILzCse8dVctQZ6fo2n/5vY5kOqpj/FkB7jSqXHRIBJU548AJQKNNG kMTucY6JxM47ScAXn9ajpXo70W/qUPLukLAjwWE9+ojyfFRbMZi5vqLHkoU63Dgofv1a wLVg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771973039; x=1772577839; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0vyzXs6Nuf3YPypneYs9PIt3O29SiUmlFmPJ2dtgRHo=; b=1BaXKsn2VaTCfMOCT0m2y2m5Xt8drA3V4QiQzOc6mOR0ujDvNcSMixL3BivY1r2YlO bSKa45P9L/IfNOIKf+AQf3GIFRT8zL/FsdBG3gwRY9s+PCVEQVMkyjumOcruIrD0GRrd EfGoNOvqsA/ivRTjpHHdjVZHZxh/X4uxtl/7cnROFgjNgI93wye8eSlSbWnBCpHIqs22 nQ2KCTU3/6hZnPTG4O5K7BxrOcHtWPMLTm07NJ6lsPfWAlGDq3Dh7XWZ77i157ofFm/P WTrxJknE3WiePC1y1oO1soP+w2PVdBq8iNmDa4scP8u0JWlLH6Rr8JHzsqmubUenBj35 jRAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771973039; x=1772577839; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0vyzXs6Nuf3YPypneYs9PIt3O29SiUmlFmPJ2dtgRHo=; b=S3TvrhQnpQfXXqoHWIrshrogmKS4iKWNiq0A8gfkoSjGglY5xcTY4CSFAJnAVenGWT /pWys1tT8moBBnk7cyT0IX4P9Z+uzagry4ynQyTsuIINH/jIjiqc41lzqLsRfZJYeAKD cK22O82AXKWmf5jdC4Kv3ivTCgAByWXupK7TX4AgeWHJmIPD4/hvUrz1phOtmrsCT/jc 8Bk0lyd0ETYILx8rRy0Vd1iyuet4iJ+AsPlb4JXsTFDIVzxobKHwAIdFVnUTfVxLuFJg vECWp5ABheqLPcE8ofC/jMQi1QSsR8ftXlvBJQ6TJVci5EB6ZOuy2F/kodiBQO44mvAQ xcZw== X-Forwarded-Encrypted: i=1; AJvYcCXXhTBy6TqU3zPpvQUd+VWrGY2ZXzP7Isej1VEOZd7Fo81HepkZ2ib1WvcgEsm6GYHiP/S/POnO6Jx6sQE=@vger.kernel.org X-Gm-Message-State: AOJu0YxM6KYlkXs7TZ5yRmmIprXuJbz4we0oCF5yqoMlxEF/kMll8AEV HOXikrXIeWo6vu5aVW/URlu8dS2OtL5KhkbUKiRDUvbemMEqrfqkMus1J8WPGZYOP2ebGEcQfh9 yvq7vwU18lkP4bsRbME6bvegjxbYJ9r+8OsY12eJn X-Gm-Gg: ATEYQzwNSfGB9VPxg7/GTLBK4zoJfAgocjXp1Pg2m7jTMikqncFpnjeW+hjK9UsevEh bs8l9kcroYbM5+m27zl8L+e6pRY/x7ou/8pZstLuaEYufpkj54wW9+/dF64/8kkXasu9PvqXW1g WgMGWVKOyS1SC5VcDWy+Uc08LMsJ5omoe045ooB1hPtpUTxPaTK1ZwOR/rYIhXZjP1zYzA02O3W C8xi2sBhBAk/SkCwA20pjw1J39NSxHcWrHkrWlgo6nu9Tq17Fa9mGb3FdC9QI4eXuhFu/laOfRt 1STCT5Bwjg9Zby1GqAXpX+736Dn8ObqJLKPcfg== X-Received: by 2002:a05:7022:128d:b0:11d:f44c:ad97 with SMTP id a92af1059eb24-1276ad11a13mr5314920c88.24.1771973039031; Tue, 24 Feb 2026 14:43:59 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260223222226.work.188-kees@kernel.org> <202602241316.CFFF256ED6@keescook> <202602241440.1D885B8@keescook> In-Reply-To: <202602241440.1D885B8@keescook> From: Marco Elver Date: Tue, 24 Feb 2026 23:43:22 +0100 X-Gm-Features: AaiRm530nNUyIcHEvt2U9h7SlrZ-STR58Elq_z7lf5SVlQwk7vDX4kQaD1idsQ0 Message-ID: Subject: Re: [PATCH] kcsan: test: Adjust "expect" allocation type for kmalloc_obj To: Kees Cook Cc: Nathan Chancellor , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 24 Feb 2026 at 23:41, Kees Cook wrote: > > On Tue, Feb 24, 2026 at 01:48:51PM -0800, Kees Cook wrote: > > On Tue, Feb 24, 2026 at 11:09:44AM +0100, Marco Elver wrote: > > > On Mon, 23 Feb 2026 at 23:22, Kees Cook wrote: > > > > > > > > Instead of depending on the implicit case between a pointer to pointers > > > > and pointer to arrays, use the assigned variable type for the allocation > > > > type so they correctly match. Solves the following build error: > > > > > > > > ../kernel/kcsan/kcsan_test.c: In function '__report_matches': > > > > ../kernel/kcsan/kcsan_test.c:171:16: error: assignment to 'char (*)[512]' from incompatible pointer type 'char (*)[3][512]' > > > > [-Wincompatible-pointer-types] > > > > 171 | expect = kmalloc_obj(observed.lines); > > > > | ^ > > > > > > > > Tested with: > > > > > > > > $ ./tools/testing/kunit/kunit.py run \ > > > > --kconfig_add CONFIG_DEBUG_KERNEL=y \ > > > > --kconfig_add CONFIG_KCSAN=y \ > > > > --kconfig_add CONFIG_KCSAN_KUNIT_TEST=y \ > > > > --arch=x86_64 --qemu_args '-smp 2' kcsan > > > > > > > > Reported-by: Nathan Chancellor > > > > Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types") > > > > Signed-off-by: Kees Cook > > > > --- > > > > Cc: Marco Elver > > > > Cc: Dmitry Vyukov > > > > Cc: > > > > --- > > > > kernel/kcsan/kcsan_test.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c > > > > index 79e655ea4ca1..056fa859ad9a 100644 > > > > --- a/kernel/kcsan/kcsan_test.c > > > > +++ b/kernel/kcsan/kcsan_test.c > > > > @@ -168,7 +168,7 @@ static bool __report_matches(const struct expect_report *r) > > > > if (!report_available()) > > > > return false; > > > > > > > > - expect = kmalloc_obj(observed.lines); > > > > + expect = kmalloc_obj(*expect); > > > > > > This is wrong. Instead of allocating 3x512 bytes it's now only > > > allocating 512 bytes, so we get OOB below with this change. 'expect' > > > is a pointer to a 3-dimensional array of 512-char arrays (matching > > > observed.lines). > > > > Why did running the kunit test not trip over this? :( > > > > Hmpf, getting arrays allocated without an explicit cast seems to be > > impossible. How about this: > > > > > > diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c > > index 056fa859ad9a..ae758150ccb9 100644 > > --- a/kernel/kcsan/kcsan_test.c > > +++ b/kernel/kcsan/kcsan_test.c > > @@ -168,7 +168,7 @@ static bool __report_matches(const struct expect_report *r) > > if (!report_available()) > > return false; > > > > - expect = kmalloc_obj(*expect); > > + expect = (typeof(expect))kmalloc_obj(observed.lines); > > if (WARN_ON(!expect)) > > return false; > > Or: > > expect = kmalloc_objs(*observed.lines, ARRAY_SIZE(observed.lines)); > > I think the quoted cast is probably better... The cast is easier to read (no indirection needed to understand it's just allocating same size as observed.lines).