Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp114126iof; Sun, 5 Jun 2022 22:48:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx55POHKw0aB+L8tedCWCfB+sv+czx+mDGgbHCZtEkmuhCFHI5Dxj4JsRTz/1pMKHUhmD1s X-Received: by 2002:a63:1359:0:b0:3fd:a384:d69c with SMTP id 25-20020a631359000000b003fda384d69cmr4933941pgt.289.1654494486249; Sun, 05 Jun 2022 22:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654494486; cv=none; d=google.com; s=arc-20160816; b=we818BCfsilAM89iaJhK6bVNfOU5IDIp/7OTN8+R/KzFBsz3iUf9uKsQ087g/KAfrN JThi1TuQRZrzUwyE22rR2afMP/iNDdDO699O1LbJrBbMe8RQShinXN30K9MEnc2IjsHU sQkn5BcGwO+sY6q7yqpS6twfdwa4vErZrHtptT34Ymyy3B7OGOtvbHp95pU6iCa+TDvx 32gfzKFSe9wEOSAtCji/g4EvmUN5GTkcQ2ysuF+HuBmlRpbqyNjYkGX7PZsInfCDOUdL DoZ48L3XAIigh68BDqWOMPGxYGwmvXsgUtYKwDwojEd0yAqps4jGjKv3B7f+B+QwRzm8 e4kA== 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=t9eO2W+TDWyB/EPkJdLANIjxz/dfZCq20HVaE3dtXpI=; b=n0Q8Owo8h0yOaDHyt+uhNJrzqlWhmoS29mATv5PvNUg37YmrVMgwraS7zM9E1aAVZK jVonnkiBrQZEP3vHsjF50VXM+ilaLw7pY8TtHM+6NocK+pbbcqAOBfaHG0MfckQn76Rl OoB1qDGfeIsrl9k3fWdv1BaNTZzI2pB9SRgu1vgma3A6It1qL1H2bD8x/ETZlo+WCffm qH64BnDlXI81l4laJ6Mj2/vakdYF8Jv8WMs86mZpN1R37lApCItYQ/gCwxGMD3oDwSSB 5QRcJcmCnzmkd5fex4YaRNV6+Y+I/sjtiayOf7U0W4hIxmJuMUGUcfyoz7pQ6dYpF1mM nKuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K+FdT5wm; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id cm18-20020a056a00339200b0051bc46f9672si16338265pfb.45.2022.06.05.22.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:48:06 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K+FdT5wm; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37ED225C1FD; Sun, 5 Jun 2022 21:38:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346688AbiFCSTd (ORCPT + 99 others); Fri, 3 Jun 2022 14:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347869AbiFCSG0 (ORCPT ); Fri, 3 Jun 2022 14:06:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED1E65D5E0; Fri, 3 Jun 2022 10:59:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B10D861555; Fri, 3 Jun 2022 17:59:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F920C385B8; Fri, 3 Jun 2022 17:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654279164; bh=EPBHgmukQQ2kavRRx6NFY8j/vcnjOWl5lgESjAPm9W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K+FdT5wmZQycc4wxKQp06QjZZcm45uvmVM52PdQuFqZP9+RLoMAQfr+wB+h6EqQlA WiaXBprIzeBjOAW0GSNcZao5YHAxIYwjsaYdBB5SmlrgeI7hj2ntlJ6qeXCPGS89R9 xiPlEp8793XGDjR1VomIBEfEGbqih/gm9lPil1SA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Randy Dunlap , syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com, Namjae Jeon , Konstantin Komarov , Alexander Viro , Kari Argillander , Matthew Wilcox , Andrew Morton Subject: [PATCH 5.18 44/67] fs/ntfs3: validate BOOT sectors_per_clusters Date: Fri, 3 Jun 2022 19:43:45 +0200 Message-Id: <20220603173822.000588901@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173820.731531504@linuxfoundation.org> References: <20220603173820.731531504@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Randy Dunlap commit a3b774342fa752a5290c0de36375289dfcf4a260 upstream. When the NTFS BOOT sectors_per_clusters field is > 0x80, it represents a shift value. Make sure that the shift value is not too large before using it (NTFS max cluster size is 2MB). Return -EVINVAL if it too large. This prevents negative shift values and shift values that are larger than the field size. Prevents this UBSAN error: UBSAN: shift-out-of-bounds in ../fs/ntfs3/super.c:673:16 shift exponent -192 is negative Link: https://lkml.kernel.org/r/20220502175342.20296-1-rdunlap@infradead.org Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Signed-off-by: Randy Dunlap Reported-by: syzbot+1631f09646bc214d2e76@syzkaller.appspotmail.com Reviewed-by: Namjae Jeon Cc: Konstantin Komarov Cc: Alexander Viro Cc: Kari Argillander Cc: Namjae Jeon Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/ntfs3/super.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -668,9 +668,11 @@ static u32 format_size_gb(const u64 byte static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot) { - return boot->sectors_per_clusters <= 0x80 - ? boot->sectors_per_clusters - : (1u << (0 - boot->sectors_per_clusters)); + if (boot->sectors_per_clusters <= 0x80) + return boot->sectors_per_clusters; + if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */ + return 1U << (0 - boot->sectors_per_clusters); + return -EINVAL; } /* @@ -713,6 +715,8 @@ static int ntfs_init_from_boot(struct su /* cluster size: 512, 1K, 2K, 4K, ... 2M */ sct_per_clst = true_sectors_per_clst(boot); + if ((int)sct_per_clst < 0) + goto out; if (!is_power_of_2(sct_per_clst)) goto out;