From patchwork Fri Feb 23 14:20:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 205421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp615303dyb; Fri, 23 Feb 2024 06:21:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVSnmoKY30e5GZrR8LyLfVzm9BpO+D5hFQP1L1FfPZHxJAIgZ3cQaVSUpPZtg51XUQfQRoKmAqqsCH0Z1y0GZ0eegBt2w== X-Google-Smtp-Source: AGHT+IEuOf9Fnuyg0d+ZySD0Tp0d9qDWOK2pHQjiC+m7pwF4Q3OSmgZDja/ZhUapkj4eSH12o9AV X-Received: by 2002:a05:6a20:2d28:b0:19e:cf1a:5369 with SMTP id g40-20020a056a202d2800b0019ecf1a5369mr3205588pzl.24.1708698106193; Fri, 23 Feb 2024 06:21:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708698106; cv=pass; d=google.com; s=arc-20160816; b=BbMwoy9RTyrzA1/a5tqgEQJVVjuLE8s22kf/Ta2hm9tsjUN08YFriL7uzdm86bzY5V T+YeuoMwf2XNKNZxCk3Vc/a/Rkd80iFPBT8SGvieZjxKCht68oHhrDKqDZQwbzMBboXt qVOZ1uiIiI9g3dVNy+W4z15rjWhUfe3qrQw6v3UmPDGkC8bVg7SOR10bCAgVFCJsjc+L GG021aVC70HaUX6JKlEZI66uRIXIbyQ1ENb/qEXg17OIcJ/ni8Q6vnMdFsWA074SoTIp fjzA3KtcI11N+wmdQwc5w0Nii/xsY+oTPzZhXyGak6c2aTC+2R+m8bEpJXcGlrIsdsIc rqdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=y2AYcb7BkAamBT8laTS5yV6Xd89bfL5FSrmzKjPqhBc=; fh=FdTpvYRzl0El+EgYcfotqsAbvS8eD63DMIHTQwG+Ar4=; b=D2vKjVqgsOc/wJ3nbsfmVitvWUXiy1ibxG0sWOH5G2m02SJFaWQprrEV9XiBTnDJQ6 6+y3yAywUAFiNGRhAjTJkboumZlAyuOBSqZhcaTAxXnvASLs1zKVDg1+67f7P8s4dNUf ETWHqSCoIWVGEUQ+uJ1RA6DlUXIoYQDhpWHjrgbQY/7hxsg7gJ78d0+PB4R5nuev4aCH SMv7oQM3v8VITb4EYmh+plGaEhl1BOcsCoNRaRU4yxCxWoUHuYcfjLK8QFuYEuZ8xK/B TEn6Xd0VoK96ypvXbi7L4hhW4lsZ9k5oE+qVaVlHnMn64JLOhshfCbCdVopJUzOy68An NK/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uw1QsRTX; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-78472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78472-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r25-20020a62e419000000b006e37d642b66si11089868pfh.183.2024.02.23.06.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:21:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uw1QsRTX; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-78472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78472-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 46DB0B21AEC for ; Fri, 23 Feb 2024 14:21:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCA8581AD0; Fri, 23 Feb 2024 14:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uw1QsRTX" Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 747D66FBF for ; Fri, 23 Feb 2024 14:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708698020; cv=none; b=daJTJHw0RHDpBKPeD6harx/pHfD423/xkJkh/Vqlv9Aa2QDcgAR3o5hk4lDrTxDlJjVK7xxvlg79PfQP1fuUgFJASxkyxdr7aNbF2Ufxi2UrVtmfV57d6uEG75+TXxZpwZjVQvJ/E+w0Knvt3HYxgNF8vx3Iig62MK0Cavu+7LI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708698020; c=relaxed/simple; bh=P9QaVDrmjk4Jn91La3VhEGTQaiz1JWgebffCRbAeQP0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=EhwBWR8099HlC3MLubXajUmjjA85CXWwz+sDXGev2+6AM5sp4lJovj/kW2hK1zXy9AawnnBPonhsyEmnRIn0Quc3fK7SgR057iYPqZexp47Bo8+ErFZsqN/fulf8E3yJDdSxtUJmBaZXqAt8E5VEUyz+tcTaIBKuZ+dac41c2Vc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=uw1QsRTX; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4127190ad83so6004015e9.0 for ; Fri, 23 Feb 2024 06:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708698017; x=1709302817; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=y2AYcb7BkAamBT8laTS5yV6Xd89bfL5FSrmzKjPqhBc=; b=uw1QsRTXWuPeSb/2UJqVI1qeWx9300OaT5dSuuKDMWAkfUKeInP2uJiSHOYydBI9kh sgQC/CM47/aBex7bremuF6BDQuaQ+fx1buPWddMGixBNxZ0KNlo95laS7zaO7u6p1oFx E1mdLEIBPU2higXQP/Z85TJ4EMhHiNvSXW2jstFN4etqhtqHV8ssykCouyxm2p6zjTCc CPY9iPf40Tu/igDZ5cVMVtlXLJ+dHxWfk0x3V5Y1ZpUFZZrsNkxza/1fc7srvZmJDuEz WNFKl15Mi3jDycgZyv71iSsV/J6SZMnmv43ymr2cjrJ92syFQRnnNJfDh0Hecs8l/Fxu 5Scw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708698017; x=1709302817; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y2AYcb7BkAamBT8laTS5yV6Xd89bfL5FSrmzKjPqhBc=; b=KegJcP/3PHWGmUdZ6Q2jysaftyUkTJ+6AhNFJzA8jNj+UGxjpoZjMX2TLbIG9HvyOy gHiu2VjTpE8XdvC4k2ShI5xedZs9ULwIrgURY7vimRjSx/Xzw60kHkhiz1bKxYExsvtI eqcRCDw8DBCebWmVKTcBdcY4FEfq8FASOWefYlsvB5dQI/DKS8lTHBD9TFDxEWtP3SYG FohUjB+x5Q44zdvXN35o8pZzYI33rB75KFF+dwzfp7eq+M0atsymbyk54rI85O/9cqc3 1W+O5a0XQSPUrmEA1NmSVY139UpCbYQp/oTlRiB4fTkkUbtzeZOqpkADJMX1tsr+Tqtt oXeQ== X-Forwarded-Encrypted: i=1; AJvYcCV4xPEpQKwMU98q+PcrxBygPJPgbxgEnNb4CSx4CrB5duVhHoM5AxnqzYCh61AhpS9us+cRtIgsoNB518ONqk3o3cXGXlc5acLu+s28 X-Gm-Message-State: AOJu0YzD2N/6O1awf9lNPelfABUY3zwfptKICVaMmaVh90ExdKihNUag O7oPr9dRZPMiutUoGQUF5qoZP5orOpTPPpu1KhlX6Y7VNRQoctRM7G1qy4EKWkE= X-Received: by 2002:a05:600c:3051:b0:412:78da:8abe with SMTP id n17-20020a05600c305100b0041278da8abemr1408960wmh.30.1708698016772; Fri, 23 Feb 2024 06:20:16 -0800 (PST) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id dq8-20020a0560000cc800b0033ce5b3390esm2966338wrb.38.2024.02.23.06.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:20:16 -0800 (PST) Date: Fri, 23 Feb 2024 17:20:13 +0300 From: Dan Carpenter To: Andrey Konovalov Cc: Andrew Morton , Alexander Potapenko , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] lib/stackdepot: off by one in depot_fetch_stack() Message-ID: <361ac881-60b7-471f-91e5-5bf8fe8042b2@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791699825442275052 X-GMAIL-MSGID: 1791699825442275052 The stack_pools[] array has DEPOT_MAX_POOLS. The "pools_num" tracks the number of pools which are initialized. See depot_init_pool() for more details. If pool_index == pools_num_cached, this will read one element beyond what we want. If not all the pools are initialized, then the pool will be NULL, triggering a WARN(), and if they are all initialized it will read one element beyond the end of the array. Fixes: b29d31885814 ("lib/stackdepot: store free stack records in a freelist") Signed-off-by: Dan Carpenter Reviewed-by: Andrey Konovalov --- From static analysis. What seems to have happened is that originally we stored the highest index instead of the number of elements and when we changed the > to >= comparison was overlooked. lib/stackdepot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 8c795bb20afb..af6cc19a2003 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -447,7 +447,7 @@ static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle) lockdep_assert_not_held(&pool_lock); - if (pool_index > pools_num_cached) { + if (pool_index >= pools_num_cached) { WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", pool_index, pools_num_cached, handle); return NULL;