Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp528142pxj; Tue, 18 May 2021 08:38:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoSQKf8Wd5rMhya3U+pewTzIENGcW8W9Zn3wdcbaGnItWX/W1HNytSvv4VaGYKgO2aQOa3 X-Received: by 2002:a05:6602:21d7:: with SMTP id c23mr4739350ioc.147.1621352281742; Tue, 18 May 2021 08:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621352281; cv=none; d=google.com; s=arc-20160816; b=bUI0meNB8jYBIg+5wdFXk5XVzvRag+ul4du1hQdVeXXqv40GMSyL9lKl8hHh5h5fn5 cr5M9sZ4MGEz2BxFYEDKciZXf1OWXQdOM8fIx8c26ke2gB9kZ3VmYH2bIWB0V58qET7r eWCSelXDD+ZJJU3Nl3qudl+XR3G512wpqYpwmnhmYOKDXGwVCu1xjNZ+tew6PjBZprXc wmYLELzrRdxoTMfaiKPBbJU17AtXbRVdBuPmS2we9NhEMLv50aWblf8lFm6jBVRc0+ee pNcZx5TdY2Od+vE3dsz/7QoERoH9MZDmehllsrrcc2Yel5//JcdwYyu3M9MVHMbWGCrR iElw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oi+j+N7qeaYPUFtDByW98TT2dEVXhnbeZjgCwqketx0=; b=k7bPWK420tT//vBVTAyzo9kF3iXmAD5ZeYeZgBM+Mkcxtmqw4WIMthFWgB8AmbwMah 3Ivguy+KlZ0sqSk7i7yS5xafVclJ3hpKo9RpDrLd76RNWIUj1h0iIp08KVfe8S3xD+ZK Jf7ca1f47G2AtXcexyel36F1RWguiDU0KurPMO1bX0+utBrdJqSvedws/EpC0bcWwdsD moHBsxkkSpSqUKlorRIoQY8Grd7G6tYt64XV78NrzIICfoFO9/PFtwC5KI5dwawou5zk AGLx4juRzrY4wd8IOvxfamwPHdAafvJ03DX5M2xM+u0SHr+rp+1URiW6QjAL0lf+m2A3 8FVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mB30GnTd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s7si25427084ilu.0.2021.05.18.08.37.30; Tue, 18 May 2021 08:38:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mB30GnTd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345263AbhEQPyh (ORCPT + 99 others); Mon, 17 May 2021 11:54:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:40236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244186AbhEQPgn (ORCPT ); Mon, 17 May 2021 11:36:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8D25E61402; Mon, 17 May 2021 14:40:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262407; bh=tcUVMuMgLyyT89/cUG1U/0KGN5h80q4PpF7JLCOk/Ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mB30GnTdEuzxgVtw85yjolxwTcoNEi/t/yIKIlnpdt9jNPY6SdEI62y3zW0hT0A7o ppTcKIeKdzwuq1/ifl8nehaYuOBjomcLeMVvFT275Plj4chUbWvRW4v9kKefS76z+8 1NvD6KOjFhRM8mFpZLrmMPu96XYqX005TCYALPU0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qais Yousef , Quentin Perret , "Peter Zijlstra (Intel)" , Vincent Guittot , Dietmar Eggemann , Sasha Levin Subject: [PATCH 5.10 181/289] sched: Fix out-of-bound access in uclamp Date: Mon, 17 May 2021 16:01:46 +0200 Message-Id: <20210517140311.204516622@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Perret [ Upstream commit 6d2f8909a5fabb73fe2a63918117943986c39b6c ] Util-clamp places tasks in different buckets based on their clamp values for performance reasons. However, the size of buckets is currently computed using a rounding division, which can lead to an off-by-one error in some configurations. For instance, with 20 buckets, the bucket size will be 1024/20=51. A task with a clamp of 1024 will be mapped to bucket id 1024/51=20. Sadly, correct indexes are in range [0,19], hence leading to an out of bound memory access. Clamp the bucket id to fix the issue. Fixes: 69842cba9ace ("sched/uclamp: Add CPU's clamp buckets refcounting") Suggested-by: Qais Yousef Signed-off-by: Quentin Perret Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Reviewed-by: Dietmar Eggemann Link: https://lkml.kernel.org/r/20210430151412.160913-1-qperret@google.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3c3554d9ee50..57b236251884 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -936,7 +936,7 @@ DEFINE_STATIC_KEY_FALSE(sched_uclamp_used); static inline unsigned int uclamp_bucket_id(unsigned int clamp_value) { - return clamp_value / UCLAMP_BUCKET_DELTA; + return min_t(unsigned int, clamp_value / UCLAMP_BUCKET_DELTA, UCLAMP_BUCKETS - 1); } static inline unsigned int uclamp_none(enum uclamp_id clamp_id) -- 2.30.2