Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1247861rdb; Fri, 22 Dec 2023 22:40:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQL6+A1ZnJr7BDXevOFCbcoPdelKan2ouDn7jlHxOyl1Afp5MXKjPyVZ7eMny5kHOs7K4W X-Received: by 2002:a05:6a20:8e25:b0:195:6e6b:8fa8 with SMTP id y37-20020a056a208e2500b001956e6b8fa8mr230251pzj.21.1703313636822; Fri, 22 Dec 2023 22:40:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703313636; cv=none; d=google.com; s=arc-20160816; b=WgeCyFW0iIZqGQAUTssXNPMmqfUWjDHkryykExktTXEkRmFhdyJHu+gWr2LuYv/8y1 701a5lKrdnXoF6aOyC80q11LHTKJL+N2gTDixigj3IV7BjU27NZbPr61OvkAu7c8VOCR Q9ZaWNqHzvtlDtFmmu2xgnb4mpQlB+Q2ahUv1VK+ONI+jRTF6+aSPNqB24XELdoFqEnX HucpAqvM7do1sv+cZZJiC8lUZvuVctSzhrRrpdnJwxPgifdE/L/IJs4AmIDDi2Glxixh HtiDBW+Pr/x+QgSPC52hCvc95UEnm6XDuOiwfw2NmPuaGT1f2I5vC/I6JrcFMoRQ12U7 pxtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=kZlbsd/2jFgLAl3hXPdOWshH18Q3ciwpMzC2/dxGOfY=; fh=zkcIwTk9sJN+dFrByvp4IZwwJkxOuOrldZrviqmXhTE=; b=Ym6EJdlIFafY909jYCJboLybgp+7VctuzVMpj+Dzgcnpi2MnhVtSmsZubelYaO79N0 /0UQUS4yFIDfCJoE7QKlxLILIrJwXoRVx6loI2W2zGfIymE7uIjarpIUQ1YmUG1AurQK n+B7qWnD1bsyRilMzN7PRRmLLqVQLMlJRJMGB9rFSA0Cce0MjMa6zqAN4XFGctvS5eKq HlDLPsmLdTQqNAyE6JgD00EuasU8bNKTYmBbxAUc2uQRaYPsq6JF2Pr0FB1dfbRagC69 XXfjTJSVvL+tmNODXI7ms7+gurkzoU+sUwNvlHjcDxcHyy77MlNrIpowNUrwdvtej0jI 2hqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10323-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j3-20020a63ec03000000b005cdfa599535si1906729pgh.387.2023.12.22.22.40.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 22:40:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10323-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BA563B22F97 for ; Sat, 23 Dec 2023 06:40:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B241FD270; Sat, 23 Dec 2023 06:39:41 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 6E1E46108; Sat, 23 Dec 2023 06:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SxvfB0YpCz4f3lVH; Sat, 23 Dec 2023 14:39:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 5E0EF1A0787; Sat, 23 Dec 2023 14:39:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgCXmhCjgIZlBfyaEQ--.4053S7; Sat, 23 Dec 2023 14:39:35 +0800 (CST) From: linan666@huaweicloud.com To: axboe@kernel.dk, geliang.tang@suse.com, xni@redhat.com, colyli@suse.de Cc: ira.weiny@intel.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 3/4] badblocks: fix slab-out-of-bounds in _badblocks_check() Date: Sat, 23 Dec 2023 14:37:27 +0800 Message-Id: <20231223063728.3229446-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231223063728.3229446-1-linan666@huaweicloud.com> References: <20231223063728.3229446-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgCXmhCjgIZlBfyaEQ--.4053S7 X-Coremail-Antispam: 1UD129KBjvdXoWrtFy8CFW7Zw13ur18uw1rJFb_yoWfuwc_Ca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pf9x0JU9Z23UUUUU= X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ From: Li Nan prev_badblocks() will return -1 if checked range start < p[0]. Accessing p[-1] will cause bug as below: BUG: KASAN: slab-out-of-bounds in badblocks_check+0x2c4 Fix it by checking 'prev' before accessing badblocks->page. Fixes: 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling") Signed-off-by: Li Nan --- block/badblocks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/badblocks.c b/block/badblocks.c index 054d05b93641..71a3e43351da 100644 --- a/block/badblocks.c +++ b/block/badblocks.c @@ -1316,7 +1316,7 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, goto out; } - if (overlap_front(bb, prev, &bad)) { + if (prev >= 0 && overlap_front(bb, prev, &bad)) { if (set == 0) { *first_bad = BB_OFFSET(p[prev]); *bad_sectors = BB_LEN(p[prev]); -- 2.39.2