Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp430016pxj; Tue, 18 May 2021 06:38:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKNzjnpRYEWNduYUYYwnqMj1MCnHAF3WAfdtgw0+0v5gpsGlqUHUmBtjIWdsV2CdYy4Mx5 X-Received: by 2002:a02:a81a:: with SMTP id f26mr5677052jaj.110.1621345080343; Tue, 18 May 2021 06:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621345080; cv=none; d=google.com; s=arc-20160816; b=gz7xMvPFIDTOCh02FYJkVrBAyWZGemaZV3+WAEZIbbr4cziwtbCPnEVypXRTFyU464 jq0bOgbBl4nkNuQchj+0hTWAaiS/WTChR9gMyB9DLAYbCpII8wn0NgAveCmGpIRW1cNF kD0Edn+F1p4q26/Fr9T3mW2OD6tpzaOD8hFoOV1a290mB41bgUqUs7xhpq0an3DxEjD6 CT3MY+5lsQykh8upx6zEee8y85Bv5bS88AdHxPERsa3ban2YQefA5QMNvDgPTRBeMCmf 9LLJ2rU60+TVpmgWPa4U72rMs3vpSvz31Gwoqq0qKWbdX+0qECkWUkioMeAJiItob5Lx 0hjw== 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=Q/uApEY+DlTdq8ojCWfMRQgyR2SSw8BAalgPW9zobmE=; b=OcmHLEw+09YQj7Ltlpz2lWodjooTWrfkFNdrlpqrvFqx1jVodU0UOjAk4vKMWigZj0 uF3x8hfkzkpKUKym72ow4ffiTPQXeOOR92b9eJEcC3lAT0Ilkk9M1mg5YwBR28pflJhh zzzrFWemjonDxAEKaXA0g855Rc73nC/d+EoVwH8lw4tc79nS4m6w7tjLiSlrL6Ov0FZA ecV21s8GeLSHYFyrfXsSxR0GLtPfjft7u9EMKh70jGtHZEvhs6g7T373NDCisanWOpFR mBIhMXqd5hssEk5zN0V3s9IyX4x+m6KsL43plA0pbMy8pFbxSczxNGCkMsLj7bueZGXX Y0YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JEGNhILt; 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 q10si23768361ilu.60.2021.05.18.06.37.47; Tue, 18 May 2021 06:38:00 -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=JEGNhILt; 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 S245328AbhEQPiR (ORCPT + 99 others); Mon, 17 May 2021 11:38:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244911AbhEQPWf (ORCPT ); Mon, 17 May 2021 11:22:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E28696135F; Mon, 17 May 2021 14:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262105; bh=cDpCrryJjGc0X+3RJQQYe8zzmMK99aMJzPwbC5tR6dQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JEGNhILtEKdfPJZPeHngpzwgInVyEOR6SqiT7rdfJJii8Xb7cs7EkWo0lOYrKfVDo Lx1UaVIfh1Zmwm9WbHB6V2HH0tHVUEiTIJIV2wpy13Yyhxb5qhVO8ZmwyIHmlZYhRn TeE7kfd2aeDe1FCDNr8JUfE3406NZ4BXedi9qyBE= 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.11 216/329] sched: Fix out-of-bound access in uclamp Date: Mon, 17 May 2021 16:02:07 +0200 Message-Id: <20210517140309.436457561@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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 c5fcb5ce2194..984456b431aa 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