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 659E3C3064D for ; Tue, 2 Jul 2024 12:05:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1782210E034; Tue, 2 Jul 2024 12:05:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="jlELShFt"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3ABBC10E034 for ; Tue, 2 Jul 2024 12:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719921949; x=1751457949; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=jAVApQXj7aNAQefQxEKNK4wmt12IxVDVQcJ3eHzyiU4=; b=jlELShFt/jHRVhy+52+BMT8CdogCWuyMC+BMdzLWt/jfG2gwt7xdWNZz k8PDKPB1wiiK0EagbXys821VWTwVxLEGjInT9/qHWN+XgRHuQHk9YGha6 Za/8TZE2uLksQHlOTPam2+NccNytU0fCfHvF7IzReeQOboxcaomAgbOP/ 2AqFQCp+IsQX6TWDtYHq+7FhxRAzuOOlEGIEMNBon7S8phQ9lrHqre8MH 1YzfMG43akyLjbl3a+MsB3zStO1Oulpl4ukw1NRpAY6f0IoDxJbeFAu/T grAqiw7K05OCJUVPpVeOCmYoIYCU7Tq33Yz6oDlK4yRPxGp2YZHclieqC g==; X-CSE-ConnectionGUID: hvgh7y/YREWDJkiDJJ2JqQ== X-CSE-MsgGUID: AHc4bQ7BS0qs4kp52P0yOA== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="16918274" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="16918274" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 05:05:48 -0700 X-CSE-ConnectionGUID: +BVNDblNQrmhzpRhcVEgCQ== X-CSE-MsgGUID: 63xXJAVNQ7KwClcPw/v98w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="50321961" Received: from bergbenj-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.246.179]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 05:05:46 -0700 From: Jani Nikula To: Lucas De Marchi , Nirmoy Das Cc: intel-xe@lists.freedesktop.org Subject: Re: [PATCH] drm/xe: Fix global-out-of-bounds in rule_matches In-Reply-To: <87y16k80eb.fsf@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240701153702.21824-1-nirmoy.das@intel.com> <7maqy22uryv6u37d7wapf3pweigf7znwklw7kc4avajkg2rqin@yzur4wn2la6j> <87y16k80eb.fsf@intel.com> Date: Tue, 02 Jul 2024 15:05:43 +0300 Message-ID: <87v81o80dk.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On Tue, 02 Jul 2024, Jani Nikula wrote: > On Mon, 01 Jul 2024, Lucas De Marchi wrote: >> On Mon, Jul 01, 2024 at 05:37:02PM GMT, Nirmoy Das wrote: >>>Do post-increment instead of pre-increment to fix: >>>[ 9344.404516] BUG: KASAN: global-out-of-bounds in rule_matches+0xb72/0x11c0 [xe] >>>[ 9344.411887] Read of size 1 at addr ffffffffa330b210 by task xe_module_load/248463 >>> >>>Fixes: dc72c52a42e0 ("drm/xe/rtp: Allow to OR rules") >>>Cc: Lucas De Marchi >>>Signed-off-by: Nirmoy Das >>>--- >>> drivers/gpu/drm/xe/xe_rtp.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>>diff --git a/drivers/gpu/drm/xe/xe_rtp.c b/drivers/gpu/drm/xe/xe_rtp.c >>>index 5b27f7c45ea3..f6ec8df5fc94 100644 >>>--- a/drivers/gpu/drm/xe/xe_rtp.c >>>+++ b/drivers/gpu/drm/xe/xe_rtp.c >>>@@ -121,7 +121,7 @@ static bool rule_matches(const struct xe_device *xe, >>> * Advance rules until we find XE_RTP_MATCH_OR to check >>> * if there's another set of conditions to check >>> */ >>>- while (i < n_rules && rules[++i].match_type != XE_RTP_MATCH_OR) >>>+ while (i < n_rules && rules[i++].match_type != XE_RTP_MATCH_OR) >> >> this will double check the current iteration. A better fix was posted last >> week and I will merge it soon: > > Meh, any messing with loop variables inside a for loop is a footgun. You > need a better abstraction. :p > > Even the for loop is just too clever for its own good: > > for (r = rules, i = 0; i < n_rules; r = &rules[++i]) { > > This should just be: > > for (i = 0; i < n_rules; i++) { > r = rules[i]; r = &rules[i]; obvs > > Don't make it so hard for your future self. ;) > > BR, > Jani. > >> >> https://patchwork.freedesktop.org/series/135527/ >> >> Lucas De Marchi >> >>> ; >>> >>> if (i >= n_rules) >>>-- >>>2.42.0 >>> -- Jani Nikula, Intel