Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3098090pxj; Mon, 17 May 2021 17:44:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySb0sDOYdjsjZ7ORJfe0bnuw+vqaqVHhE5Y0x4t/0z+ahPQo00B3aSlVOhbo/41Cy9Yqgk X-Received: by 2002:a17:906:a06:: with SMTP id w6mr2994913ejf.32.1621298648481; Mon, 17 May 2021 17:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621298648; cv=none; d=google.com; s=arc-20160816; b=FUzeUsySisHS2zdDz+PC8Uu+xzPM3ZVIP+LxqH8TJxRmp0G5hIYkqGOwCOKX+aMjIV xVtTP2AdfS8RCdZyS16jaPqD+EQy2GJcncm8oYYHvAkoL05ZxpScNBiDhYfNczM7KqtR vCcl7TPm4pBj7a5wyEAVGG1ob/fTCPppiO52ix1LeCId7VSJKpB70vu2Ehw+9R6RVq52 fePYr/rTDgtqGX6jX+h4kN5YDFwn3kV1l3ye/F+8oH1alKUQlj/EqU2swfLc0F2XYYtI Oi+Rh2rbYddxG9hIo1FXk3zuuGDIrw/O3JILej1O99tATjTl0A/k+jUJohAccbaqmSK0 ruAA== 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=XTc0IsctFJxqRtBhUIB4/9IGWuD8TEfrMx3uZqRFGAU=; b=v/8BFrJAsBWdPKnQS9SqaMGFOi4VESY9y9vy2ShR4NtfBWgyPiv4/DnIE/PdovQhmX HOcHQQ50rxSaoMoGQfFGh+JA9l7fu/2tsDBYtScHBlcsSOot99UQg60kjs1bmXJBhcG8 LhNf3iGEMkTnvrxbIQVr6K5EBhiBMrBvXCIFXFJRqa1NJ389aLjcDTP14LEdZYCopF9G T738XFsBr0mUEXvmZozS2BMl8GKft78WHgFoa7zQxT7idbsz1Eysxzw77RVPYQOIvg2o r88S/u0dqxVvEMYQgRRYbPq5vi/Yrthc+lc27GhrJp2c35mEg7Mjf+WK8cAtbOQ80SbE PynQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d4hUzRqG; 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 u6si15710660ejc.208.2021.05.17.17.43.45; Mon, 17 May 2021 17:44:08 -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=d4hUzRqG; 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 S239823AbhEQO3S (ORCPT + 99 others); Mon, 17 May 2021 10:29:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239618AbhEQOYa (ORCPT ); Mon, 17 May 2021 10:24:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D0D17613D2; Mon, 17 May 2021 14:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260778; bh=JtbkjOVcdOzg7fuOsD2FsRSo5xPf7YLGyq6iAL+LiME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d4hUzRqGsxI7HF37HeeaXtoZzOa85+USJxBhZflVA+Qz413ZdyZs/qvWUznUJjlXb mXRy7AEEQJSJpFca/pR8aczo/lNyaC4uznyJSF5j4CMf2uw+/ySLMCYGw0A1r3QSan XOi5vgEGiPAUUOW06rvuaTsa+Eduyonk5KkD4PoI= 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.12 234/363] sched: Fix out-of-bound access in uclamp Date: Mon, 17 May 2021 16:01:40 +0200 Message-Id: <20210517140310.494339158@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 17ad829a114c..814200541f8f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -928,7 +928,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