From patchwork Wed Nov 29 15:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 171424 Return-Path: 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 + 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 ); 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 ; 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 To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= CC: Nikita Zhandarovich , "Pan, Xinhui" , David Airlie , Daniel Vetter , , , 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 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: 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 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 --- 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;