Message ID | 20231129152230.7931-1-n.zhandarovich@fintech.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp412912vqn; Wed, 29 Nov 2023 07:23:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0iXt2E8sq27aasxM9QuWrAme8HAK9IF3jbVhNuTeCbm2EtdWgxn9znUxJilIb2DQdRJb0 X-Received: by 2002:a05:6a20:3d85:b0:187:dd5f:93b6 with SMTP id s5-20020a056a203d8500b00187dd5f93b6mr19808244pzi.43.1701271391217; Wed, 29 Nov 2023 07:23:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701271391; cv=none; d=google.com; s=arc-20160816; b=LnlOWrkf0pwz3Up4n5dw5UqKvMjz/O9k2F4gTrQay1eV3ghMwZlE2DU08D2BA4lBUn G9Zizh2pTKMTYHawAdu2YJVpih3xlrOCzrSyOHVa264zJgnXLWF8ZZKBwnz9hLeQiw3B Ll6GFEgmspHpfOP1YUbTT22qXLbJPyMCF3aBiq2nmLjQHD31aCo2WoqoNydTVd1oE5MD fft8A0WmPVVeAT8RiymLOpuQpJqSbig9L3lxMBq9R+qpAG7xCJ4l/4aITOev5LhZ6Yrb 9NNcl/jjB4jbr5AK3DiYs6mCKf4u3ZeWW8oPRsqQ8VToMevMhNs5+JacjsM318YE92wT 8Q4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uTdFkDTBn0f1kO9rBqt6y0HDNC5rbr6HykkuiVcyysk=; fh=4q22HGY2eDjQm55VTqpfb+Hmc/Gy9Op0J9PRh2oVBhc=; b=TUATNn5tuj0JW9fwXj8BVoSV/aBYZrQPe9JL0mF7O5jKrhqITPXUbI+nI7v2KcmOCW /Y4ghWWdSCHDR3cK3ZPZDTJK9EHxv+32/hkQuezf86E6TMTAhCHOthYmhdnxaEX/zySq vDoGbIEAAdhiZNTf8KcWFGP2ch70CoVW7gcCAuB3JGCtwJMgvevC42JDTcsvRBxJTtan iEOo2/pm2MUedyvMTobReIKjv9KddmB/6kTEI/Kv7v8gYoh/i6v73GoFeL3bD0Lb/2aF IVwt95Z/CCMSOA6h+Dc3Yb8CcYyPq4gjVBAX/ZIJ0AWhNrDV8i+3mgpaEJqvYpzbt6AH oquQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u1-20020a62d441000000b006cd8db94631si6698198pfl.365.2023.11.29.07.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 07:23:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1B18280B79F8; Wed, 29 Nov 2023 07:23:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234862AbjK2PWd (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Wed, 29 Nov 2023 10:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234860AbjK2PWa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 29 Nov 2023 10:22:30 -0500 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76755E6 for <linux-kernel@vger.kernel.org>; Wed, 29 Nov 2023 07:22:36 -0800 (PST) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Wed, 29 Nov 2023 18:22:34 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Wed, 29 Nov 2023 18:22:34 +0300 From: Nikita Zhandarovich <n.zhandarovich@fintech.ru> To: Alex Deucher <alexander.deucher@amd.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com> CC: Nikita Zhandarovich <n.zhandarovich@fintech.ru>, "Pan, Xinhui" <Xinhui.Pan@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, <amd-gfx@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH] drm/radeon/r600_cs: Fix possible int overflows in r600_cs_check_reg() Date: Wed, 29 Nov 2023 07:22:30 -0800 Message-ID: <20231129152230.7931-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 29 Nov 2023 07:23:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783912350082385046 X-GMAIL-MSGID: 1783912350082385046 |
Series |
drm/radeon/r600_cs: Fix possible int overflows in r600_cs_check_reg()
|
|
Commit Message
Nikita Zhandarovich
Nov. 29, 2023, 3:22 p.m. UTC
While improbable, there may be a chance of hitting integer
overflow when the result of radeon_get_ib_value() gets shifted
left.
Avoid it by casting one of the operands to larger data type (u64).
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: 1729dd33d20b ("drm/radeon/kms: r600 CS parser fixes")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/gpu/drm/radeon/r600_cs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
Am 29.11.23 um 16:22 schrieb Nikita Zhandarovich: > While improbable, there may be a chance of hitting integer > overflow when the result of radeon_get_ib_value() gets shifted > left. > > Avoid it by casting one of the operands to larger data type (u64). > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. Well IIRC cb_color_bo_offset is just 32bits anyway, so this doesn't change anything. Regards, Christian. > > Fixes: 1729dd33d20b ("drm/radeon/kms: r600 CS parser fixes") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > --- > drivers/gpu/drm/radeon/r600_cs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c > index 638f861af80f..6cf54a747749 100644 > --- a/drivers/gpu/drm/radeon/r600_cs.c > +++ b/drivers/gpu/drm/radeon/r600_cs.c > @@ -1275,7 +1275,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > return -EINVAL; > } > tmp = (reg - CB_COLOR0_BASE) / 4; > - track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8; > + track->cb_color_bo_offset[tmp] = (u64)radeon_get_ib_value(p, idx) << 8; > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > track->cb_color_base_last[tmp] = ib[idx]; > track->cb_color_bo[tmp] = reloc->robj; > @@ -1302,7 +1302,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > "0x%04X\n", reg); > return -EINVAL; > } > - track->htile_offset = radeon_get_ib_value(p, idx) << 8; > + track->htile_offset = (u64)radeon_get_ib_value(p, idx) << 8; > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > track->htile_bo = reloc->robj; > track->db_dirty = true;
On Wed, Nov 29, 2023 at 10:47 AM Christian König <christian.koenig@amd.com> wrote: > > Am 29.11.23 um 16:22 schrieb Nikita Zhandarovich: > > While improbable, there may be a chance of hitting integer > > overflow when the result of radeon_get_ib_value() gets shifted > > left. > > > > Avoid it by casting one of the operands to larger data type (u64). > > > > Found by Linux Verification Center (linuxtesting.org) with static > > analysis tool SVACE. > > Well IIRC cb_color_bo_offset is just 32bits anyway, so this doesn't > change anything. All of the GPU addresses in the structure are u64. The registers are 32 bits which is why they are 256 byte aligned. That said, I think the MC on the chips supported by this code are only 32 bits so we shouldn't see any addresses greater than 32 bits, but this seems like good to do from a coding perspective. Otherwise, we'll keep getting this patch. Alex Alex > > Regards, > Christian. > > > > > Fixes: 1729dd33d20b ("drm/radeon/kms: r600 CS parser fixes") > > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > > --- > > drivers/gpu/drm/radeon/r600_cs.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c > > index 638f861af80f..6cf54a747749 100644 > > --- a/drivers/gpu/drm/radeon/r600_cs.c > > +++ b/drivers/gpu/drm/radeon/r600_cs.c > > @@ -1275,7 +1275,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > > return -EINVAL; > > } > > tmp = (reg - CB_COLOR0_BASE) / 4; > > - track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8; > > + track->cb_color_bo_offset[tmp] = (u64)radeon_get_ib_value(p, idx) << 8; > > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > > track->cb_color_base_last[tmp] = ib[idx]; > > track->cb_color_bo[tmp] = reloc->robj; > > @@ -1302,7 +1302,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > > "0x%04X\n", reg); > > return -EINVAL; > > } > > - track->htile_offset = radeon_get_ib_value(p, idx) << 8; > > + track->htile_offset = (u64)radeon_get_ib_value(p, idx) << 8; > > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > > track->htile_bo = reloc->robj; > > track->db_dirty = true; >
Am 29.11.23 um 17:03 schrieb Alex Deucher: > On Wed, Nov 29, 2023 at 10:47 AM Christian König > <christian.koenig@amd.com> wrote: >> Am 29.11.23 um 16:22 schrieb Nikita Zhandarovich: >>> While improbable, there may be a chance of hitting integer >>> overflow when the result of radeon_get_ib_value() gets shifted >>> left. >>> >>> Avoid it by casting one of the operands to larger data type (u64). >>> >>> Found by Linux Verification Center (linuxtesting.org) with static >>> analysis tool SVACE. >> Well IIRC cb_color_bo_offset is just 32bits anyway, so this doesn't >> change anything. > All of the GPU addresses in the structure are u64. The registers are > 32 bits which is why they are 256 byte aligned. That said, I think > the MC on the chips supported by this code are only 32 bits so we > shouldn't see any addresses greater than 32 bits, but this seems like > good to do from a coding perspective. Otherwise, we'll keep getting > this patch. Just double checked it, in evergreen_cs_track the fields are just 32bits, but in r600_cs_track they are 64bits. No idea if we every used the full address space, but it's probably a good point to merge it just to silence the static checker warning. Christian. > > Alex > > > Alex > >> Regards, >> Christian. >> >>> Fixes: 1729dd33d20b ("drm/radeon/kms: r600 CS parser fixes") >>> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> >>> --- >>> drivers/gpu/drm/radeon/r600_cs.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c >>> index 638f861af80f..6cf54a747749 100644 >>> --- a/drivers/gpu/drm/radeon/r600_cs.c >>> +++ b/drivers/gpu/drm/radeon/r600_cs.c >>> @@ -1275,7 +1275,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) >>> return -EINVAL; >>> } >>> tmp = (reg - CB_COLOR0_BASE) / 4; >>> - track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8; >>> + track->cb_color_bo_offset[tmp] = (u64)radeon_get_ib_value(p, idx) << 8; >>> ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); >>> track->cb_color_base_last[tmp] = ib[idx]; >>> track->cb_color_bo[tmp] = reloc->robj; >>> @@ -1302,7 +1302,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) >>> "0x%04X\n", reg); >>> return -EINVAL; >>> } >>> - track->htile_offset = radeon_get_ib_value(p, idx) << 8; >>> + track->htile_offset = (u64)radeon_get_ib_value(p, idx) << 8; >>> ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); >>> track->htile_bo = reloc->robj; >>> track->db_dirty = true;
Applied. Thanks! On Wed, Nov 29, 2023 at 10:28 AM Nikita Zhandarovich <n.zhandarovich@fintech.ru> wrote: > > While improbable, there may be a chance of hitting integer > overflow when the result of radeon_get_ib_value() gets shifted > left. > > Avoid it by casting one of the operands to larger data type (u64). > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 1729dd33d20b ("drm/radeon/kms: r600 CS parser fixes") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > --- > drivers/gpu/drm/radeon/r600_cs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c > index 638f861af80f..6cf54a747749 100644 > --- a/drivers/gpu/drm/radeon/r600_cs.c > +++ b/drivers/gpu/drm/radeon/r600_cs.c > @@ -1275,7 +1275,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > return -EINVAL; > } > tmp = (reg - CB_COLOR0_BASE) / 4; > - track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8; > + track->cb_color_bo_offset[tmp] = (u64)radeon_get_ib_value(p, idx) << 8; > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > track->cb_color_base_last[tmp] = ib[idx]; > track->cb_color_bo[tmp] = reloc->robj; > @@ -1302,7 +1302,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) > "0x%04X\n", reg); > return -EINVAL; > } > - track->htile_offset = radeon_get_ib_value(p, idx) << 8; > + track->htile_offset = (u64)radeon_get_ib_value(p, idx) << 8; > ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); > track->htile_bo = reloc->robj; > track->db_dirty = true; > -- > 2.25.1 >
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c index 638f861af80f..6cf54a747749 100644 --- a/drivers/gpu/drm/radeon/r600_cs.c +++ b/drivers/gpu/drm/radeon/r600_cs.c @@ -1275,7 +1275,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) return -EINVAL; } tmp = (reg - CB_COLOR0_BASE) / 4; - track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8; + track->cb_color_bo_offset[tmp] = (u64)radeon_get_ib_value(p, idx) << 8; ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); track->cb_color_base_last[tmp] = ib[idx]; track->cb_color_bo[tmp] = reloc->robj; @@ -1302,7 +1302,7 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx) "0x%04X\n", reg); return -EINVAL; } - track->htile_offset = radeon_get_ib_value(p, idx) << 8; + track->htile_offset = (u64)radeon_get_ib_value(p, idx) << 8; ib[idx] += (u32)((reloc->gpu_offset >> 8) & 0xffffffff); track->htile_bo = reloc->robj; track->db_dirty = true;