From nobody Sun Feb 8 18:14:05 2026 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 845B11474AB for ; Thu, 11 Apr 2024 11:08:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712833739; cv=none; b=byhj9lnwPeZ29pd5oDcBPLQ0Sxh5maqNStYf0aAx9b8WnDKGevkeDKnV8qg15iUcwON/nwhS78Un4oN8ndKC+m5gIqekMA2CYadOGHbIjqbq/sIlnHWPz1uAOZT9nCsE7Az4Vyy40aMkakUzjsn+C8Z4Krfa/goz+oMbZlwAWTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712833739; c=relaxed/simple; bh=4yerjFFTsRI1XLGWxI1mWV+vwXM2RIzb82EVWzwsnw0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cgPxS/urSHMa0GZ55Yhav/9/0ug+zAsOk0BC+iS9QLyQim3+bgLcJ1olec9/quShrZ76VDmwu2a8FvD2lfGJsM5JpTMigMiLPrKimfItuiYfVVrDJJmCbK/vVkSuxAVffknEf2xjZVNxVC6RNevm9qx7azdlExDYckUV3Sl8qzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=YeQFpoGj; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="YeQFpoGj" Received: from tundra.lovozera (unknown [178.176.79.151]) by mail.ispras.ru (Postfix) with ESMTPSA id CA9684073CFC; Thu, 11 Apr 2024 11:08:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CA9684073CFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1712833732; bh=6nS8pm5CRwKEHxdOcbSSAvsWDn+jjKR17A7PSN1Ed+k=; h=From:To:Cc:Subject:Date:From; b=YeQFpoGjy7hnaJAj9pGdBRzJT+B+l0eZezXjucGk1ztAq8+FgooxPjA7HSbzlsKEX /BOyJNhYY/7HVZ+hUXY8/6P5n9HjoULhT7geCYVvwNf/3O1hb6nh9ARWCDpLk15MVj X+4m0PHtp+ZS9iFkVFQr1mcL99sHbriovxwIa/xc= From: Mikhail Kobuk To: Karol Herbst Cc: Mikhail Kobuk , Lyude Paul , Danilo Krummrich , David Airlie , Daniel Vetter , Ben Skeggs , Francisco Jerez , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Fedor Pchelkin , Alexey Khoroshilov Subject: [PATCH v2] drm: nv04: Fix out of bounds access Date: Thu, 11 Apr 2024 14:08:52 +0300 Message-ID: <20240411110854.16701-1-m.kobuk@ispras.ru> X-Mailer: git-send-email 2.44.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" When Output Resource (dcb->or) value is assigned in fabricate_dcb_output(), there may be out of bounds access to dac_users array in case dcb->or is zero because ffs(dcb->or) is used as index there. The 'or' argument of fabricate_dcb_output() must be interpreted as a number of bit to set, not value. Utilize macros from 'enum nouveau_or' in calls instead of hardcoding. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 2e5702aff395 ("drm/nouveau: fabricate DCB encoder table for iMac G4") Fixes: 670820c0e6a9 ("drm/nouveau: Workaround incorrect DCB entry on a GeFo= rce3 Ti 200.") Signed-off-by: Mikhail Kobuk --- Changes in v2: - Instead of checking ffs(dcb->or), adjust function calls to match argument semantics - Link to v1: https://lore.kernel.org/all/20240331064552.6112-1-m.kobuk@isp= ras.ru/ drivers/gpu/drm/nouveau/nouveau_bios.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouve= au/nouveau_bios.c index 479effcf607e..79cfab53f80e 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c @@ -23,6 +23,7 @@ */ =20 #include "nouveau_drv.h" +#include "nouveau_bios.h" #include "nouveau_reg.h" #include "dispnv04/hw.h" #include "nouveau_encoder.h" @@ -1677,7 +1678,7 @@ apply_dcb_encoder_quirks(struct drm_device *dev, int = idx, u32 *conn, u32 *conf) */ if (nv_match_device(dev, 0x0201, 0x1462, 0x8851)) { if (*conn =3D=3D 0xf2005014 && *conf =3D=3D 0xffffffff) { - fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 1, 1, 1); + fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 1, 1, DCB_OUTPUT_B); return false; } } @@ -1763,26 +1764,26 @@ fabricate_dcb_encoder_table(struct drm_device *dev,= struct nvbios *bios) #ifdef __powerpc__ /* Apple iMac G4 NV17 */ if (of_machine_is_compatible("PowerMac4,5")) { - fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 0, all_heads, 1); - fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, 1, all_heads, 2); + fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, 0, all_heads, DCB_OUTPUT_B); + fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, 1, all_heads, DCB_OUTPUT_C); return; } #endif =20 /* Make up some sane defaults */ fabricate_dcb_output(dcb, DCB_OUTPUT_ANALOG, - bios->legacy.i2c_indices.crt, 1, 1); + bios->legacy.i2c_indices.crt, 1, DCB_OUTPUT_B); =20 if (nv04_tv_identify(dev, bios->legacy.i2c_indices.tv) >=3D 0) fabricate_dcb_output(dcb, DCB_OUTPUT_TV, bios->legacy.i2c_indices.tv, - all_heads, 0); + all_heads, DCB_OUTPUT_A); =20 else if (bios->tmds.output0_script_ptr || bios->tmds.output1_script_ptr) fabricate_dcb_output(dcb, DCB_OUTPUT_TMDS, bios->legacy.i2c_indices.panel, - all_heads, 1); + all_heads, DCB_OUTPUT_B); } =20 static int --=20 2.44.0