Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2627850lqt; Mon, 22 Apr 2024 17:21:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKYo6Ew5nKm7tFfFrrJoxhONK4x19lTziTtgRQ/ic9SaGvUGJYaNrgHwkVt+c8FWJj/Q1LxcfE9StoCKmbLzSMSX6wdsF39iPZRoRuUw== X-Google-Smtp-Source: AGHT+IHk4t8xrjwc3yn2rytw8+GSoXzKrAa0WzuApZBguuUTkgA3t0L4SROGwIBbDNlpEVWphqYm X-Received: by 2002:a05:6e02:1c25:b0:36c:f1d:9b29 with SMTP id m5-20020a056e021c2500b0036c0f1d9b29mr6633978ilh.19.1713831663882; Mon, 22 Apr 2024 17:21:03 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b2-20020a631b42000000b005e42b4c0c48si8324421pgm.390.2024.04.22.17.21.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 17:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154325-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=VMT4Tpsm; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-154325-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154325-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 582FE281D8F for ; Tue, 23 Apr 2024 00:20:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 777351BF6D1; Mon, 22 Apr 2024 23:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VMT4Tpsm" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 918611BED8F; Mon, 22 Apr 2024 23:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830325; cv=none; b=fHWAQ7ViWHkde6HklNl0NS/7ZGeGjixIB+TeZyOzf1K04sLKXmHi7D9mMLm6LkXsdXM7kFx7g6yuQJaC7MOoVquiL73GkRARRaWxDDo/Z+BeYOhqLQawonWGTSU8PEou/qUpdppldX+GG74lbpm+YCHhmr067yvvuRWHhUxeLnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713830325; c=relaxed/simple; bh=W9pOpOd2acGm9rUbkTrq2p4QP6XCepJzgXwMj8zQ8No=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s+W3h1RAWs74hWoSDkiLsyAvp4kgf/A/lRpyfYvmGMTvf4XIhZLD8+prEQOeBx7OnK24KE66Qo7Ek5wxQk514wc1nPwCiA6gvGHokyXhv2zeOMXb7dcf/obaAyfPXi3rNSVUFU4nxJbdN7r2MNBfdXtKffJUIXWZvpzbQPnO3Wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VMT4Tpsm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74A17C3277B; Mon, 22 Apr 2024 23:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713830325; bh=W9pOpOd2acGm9rUbkTrq2p4QP6XCepJzgXwMj8zQ8No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMT4TpsmmGcMWBbBDuMQnKWvH7+UuvxW6/p21L/Lmsgdg4b+Cqj+WIHqcDz4tewfR 8ktU1+wy0W1w37kMV5syAjJKX8JqOfAxGwf7BqBoxcvfoo12+n6Z0leqZQ1Q6ksWfP MwLiIGlGloC1mW4E7w9brJLQ53oimj0+Qz8+xvIamyK+0dcP+6awbu3GgbOsmQBxrT ijpqdEnu318btqM782leLlxixixBM5W78TWcLDpnnisUbzEYb+1+0F1V79BI3+jcP5 g8FUpq9uxOh4qHyCOCmhR8EtoLMuY0esOpSy5QWXVEBJ+cOVbGF3iIdNT/GNPJXz5c lGTLGuzDcVnFQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rik van Riel , Tejun Heo , Josef Bacik , Jens Axboe , Sasha Levin , cgroups@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 6/9] blk-iocost: avoid out of bounds shift Date: Mon, 22 Apr 2024 19:19:47 -0400 Message-ID: <20240422231955.1613650-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240422231955.1613650-1-sashal@kernel.org> References: <20240422231955.1613650-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.215 Content-Transfer-Encoding: 8bit From: Rik van Riel [ Upstream commit beaa51b36012fad5a4d3c18b88a617aea7a9b96d ] UBSAN catches undefined behavior in blk-iocost, where sometimes iocg->delay is shifted right by a number that is too large, resulting in undefined behavior on some architectures. [ 186.556576] ------------[ cut here ]------------ UBSAN: shift-out-of-bounds in block/blk-iocost.c:1366:23 shift exponent 64 is too large for 64-bit type 'u64' (aka 'unsigned long long') CPU: 16 PID: 0 Comm: swapper/16 Tainted: G S E N 6.9.0-0_fbk700_debug_rc2_kbuilder_0_gc85af715cac0 #1 Hardware name: Quanta Twin Lakes MP/Twin Lakes Passive MP, BIOS F09_3A23 12/08/2020 Call Trace: dump_stack_lvl+0x8f/0xe0 __ubsan_handle_shift_out_of_bounds+0x22c/0x280 iocg_kick_delay+0x30b/0x310 ioc_timer_fn+0x2fb/0x1f80 __run_timer_base+0x1b6/0x250 .. Avoid that undefined behavior by simply taking the "delay = 0" branch if the shift is too large. I am not sure what the symptoms of an undefined value delay will be, but I suspect it could be more than a little annoying to debug. Signed-off-by: Rik van Riel Cc: Tejun Heo Cc: Josef Bacik Cc: Jens Axboe Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20240404123253.0f58010f@imladris.surriel.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-iocost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 63a8fb456b283..fe5b0c79e5411 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -1290,7 +1290,7 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now) { struct ioc *ioc = iocg->ioc; struct blkcg_gq *blkg = iocg_to_blkg(iocg); - u64 tdelta, delay, new_delay; + u64 tdelta, delay, new_delay, shift; s64 vover, vover_pct; u32 hwa; @@ -1305,8 +1305,9 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now) /* calculate the current delay in effect - 1/2 every second */ tdelta = now->now - iocg->delay_at; - if (iocg->delay) - delay = iocg->delay >> div64_u64(tdelta, USEC_PER_SEC); + shift = div64_u64(tdelta, USEC_PER_SEC); + if (iocg->delay && shift < BITS_PER_LONG) + delay = iocg->delay >> shift; else delay = 0; -- 2.43.0