From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8066AFD377B for ; Wed, 25 Feb 2026 17:28:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D352B10E806; Wed, 25 Feb 2026 17:28:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="KAEBcLqx"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 57A2210E7F4; Wed, 25 Feb 2026 17:28:15 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 85CBF600AE; Wed, 25 Feb 2026 17:28:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39552C19421; Wed, 25 Feb 2026 17:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772040494; bh=EfgKCiH4LT3KqQiGbcQFoTpH2C7Iohqow3BAjy2YggI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KAEBcLqxCBxcuCKDvmYjsmnLQEKLDsGKgxKdqE7Kp348V6nAEWwJgqGJtaI6iymT7 RZgQB2SBCXYVFfxc/TZ3kUz9IyITdxWQaKHoqalUWKNefe52kmegj1o5j/usqD2UWW pwkG+fH+z7OtPAHHcngQ30IQ/zVmp/h6G7mtvyBWcJhDDhUhmdx2d3RlBpN4Dd54lE kg0k5/VLT5YuoC7Y/tfRNBqD60CfOTohNcE+NOS8gaHLQeIA5QqM37tHKK6Dd98iwW l5xbdiz671yprQhAgqbNjXTpJRbqIs/3WogRrsx/X00BQObWdXzHizPJ45SIxGCVEl 8crNUb/t7ITUQ== Date: Wed, 25 Feb 2026 09:28:13 -0800 From: Kees Cook To: Alex Deucher Cc: Christian =?iso-8859-1?Q?K=F6nig?= , David Airlie , Simona Vetter , YiPeng Chai , Tao Zhou , Hawking Zhang , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] drm/amd/ras: Fix type size of remainder argument Message-ID: <202602250926.E587F86@keescook> References: <20260225014317.work.103-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20260225014317.work.103-kees@kernel.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, Feb 24, 2026 at 05:43:18PM -0800, Kees Cook wrote: > Forcing an int to be dereferenced at uint64_t for div64_u64_rem() runs > the risk of endian confusion and stack overflowing writes. Seen while > preparing to enable -Warray-bounds globally: >=20 > In file included from ../arch/x86/include/asm/processor.h:35, > from ../include/linux/sched.h:13, > from ../include/linux/ratelimit.h:6, > from ../include/linux/dev_printk.h:16, > from ../drivers/gpu/drm/amd/amdgpu/../ras/ras_mgr/ras_sy= s.h:29, > from ../drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras.h:= 27, > from ../drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_co= re.c:24: > In function 'div64_u64_rem', > inlined from 'ras_core_convert_timestamp_to_time' at ../drivers/gpu/d= rm/amd/amdgpu/../ras/rascore/ras_core.c:72:9: > ../include/linux/math64.h:56:20: error: array subscript 'u64 {aka long lo= ng unsigned int}[0]' is partly outside array bounds of 'int[1]' [-Werror=3D= array-bounds=3D] > 56 | *remainder =3D dividend % divisor; > | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ > ../drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_core.c: In function 'ras= _core_convert_timestamp_to_time': > ../drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_core.c:70:19: note: obje= ct 'remaining_seconds' of size 4 > 70 | int days, remaining_seconds; > | ^~~~~~~~~~~~~~~~~ >=20 > Switch remaining_seconds to uint64_t to avoid the problems. >=20 > Fixes: ace232eff50e ("drm/amdgpu: Add ras module files into amdgpu") > Signed-off-by: Kees Cook > --- > Cc: Alex Deucher > Cc: "Christian K=F6nig" > Cc: David Airlie > Cc: Simona Vetter > Cc: YiPeng Chai > Cc: Tao Zhou > Cc: Hawking Zhang > Cc: > Cc: > --- > drivers/gpu/drm/amd/ras/rascore/ras_core.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/gpu/drm/amd/ras/rascore/ras_core.c b/drivers/gpu/drm= /amd/ras/rascore/ras_core.c > index 01122b55c98a..91e16b0b98f9 100644 > --- a/drivers/gpu/drm/amd/ras/rascore/ras_core.c > +++ b/drivers/gpu/drm/amd/ras/rascore/ras_core.c > @@ -63,13 +63,14 @@ int ras_core_convert_timestamp_to_time(struct ras_cor= e_context *ras_core, > { > int days_in_month[] =3D {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31= }; > uint64_t month =3D 0, day =3D 0, hour =3D 0, minute =3D 0, second =3D 0; > + uint64_t remaining_seconds; > uint32_t year =3D 0; > int seconds_per_day =3D 24 * 60 * 60; > int seconds_per_hour =3D 60 * 60; > int seconds_per_minute =3D 60; > - int days, remaining_seconds; > + int days; > =20 > - days =3D div64_u64_rem(timestamp, seconds_per_day, (uint64_t *)&remaini= ng_seconds); > + days =3D div64_u64_rem(timestamp, seconds_per_day, &remaining_seconds); > =20 > /* utc_timestamp follows the Unix epoch */ > year =3D 1970; Hm, 0day noticed this creates a problem on 32-bit systems: https://lore.kernel.org/all/202602251312.pq8yvrww-lkp@intel.com > ld: drivers/gpu/drm/amd/ras/rascore/ras_core.o: in function `ras_core_co= nvert_timestamp_to_time': > drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_core.c:99:(.text+0x23e): u= ndefined reference to `__udivmoddi4' > ld: drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_core.c:100:(.text+0x25= 3): undefined reference to `__udivdi3' > ld: drivers/gpu/drm/amd/amdgpu/../ras/rascore/ras_core.c:101:(.text+0x26= 5): undefined reference to `__umoddi3' I will investigate and send a v2... --=20 Kees Cook