Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp86943iof; Sun, 5 Jun 2022 21:58:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz41skskWd7/DpvChDGNWiiHmIkwXix+McEhJNc4U80jpXD5CkfU7oaMu3+XDOH5Rti+n9 X-Received: by 2002:a17:902:e74b:b0:166:4d34:3be3 with SMTP id p11-20020a170902e74b00b001664d343be3mr18363127plf.102.1654491484732; Sun, 05 Jun 2022 21:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491484; cv=none; d=google.com; s=arc-20160816; b=MdBQuyd/8Lar9lNFczm6gUKyd6qXKe0ro/lm4SEIdspCJQ5/eCz06up3gS/qQYsw8V BOnHlNItU/YRd5/jTRkWxmcoy3PMgEgZ2AGBCDt9e3wsLeQRqLcc5mT4oTYbZWdiqD3U 16BoiYmwn0u7Qx48EE1dM/n6gqUAj0apuf20r0F9cIayQx/qvEAMS5EnTu3jHZSBl0gU WaWRIsZq1lRrn0cQKWDlplwwYpyxcNs0+qslo8yhkSX3zFEoYENh2oYgC/GNtNfTrTkF 1fpda9M8ERDXdeuwpCHozfRsOAA/d35eX5Hqlp3rVF3fdxq00RQDQendCRuNhg/UHUup DdMQ== 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=zlJ48DbOPP65NmEg7DdulJcqpaTTqLSTHGOP/W3AoZmCA/gB/9vrwpXjLk3TosY12t Lbe3+8gjtuvmw/Bc8lw1KU4hz1avdbSRG9Hr7qykTFBvgpigXfgH22G4e3JyeQPrxufP KgYdPHW+CoXbodmeZ28CfT0gtq2VQ9kdid8L2z4FPgBFEtVVTOp8xmuG7NmS/rZ+Fv1I 4hHFt/HDyChocPmC7pO1Jm0Y2h8dG/tWkiaV8Qg89cNm0YzTQ7uQpvd7ylAF5YZm09I4 u2p6QTGRq+IZJRibri1oz4+Hg3kHuxoqGj8gWTggQQtVzs8R7f7UzZ+5KLiQvKLtKYRE roKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=U4t7hFXa; 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 s24-20020a17090aa11800b001e66ea39810si6163788pjp.37.2022.06.05.21.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:58:04 -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=U4t7hFXa; 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 A5DF6F507F; Sun, 5 Jun 2022 21:11:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346282AbiFCSBF (ORCPT + 99 others); Fri, 3 Jun 2022 14:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347228AbiFCRwI (ORCPT ); Fri, 3 Jun 2022 13:52:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBA7B54; Fri, 3 Jun 2022 10:50:46 -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 ams.source.kernel.org (Postfix) with ESMTPS id 979F7B82189; Fri, 3 Jun 2022 17:50:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1F54C385A9; Fri, 3 Jun 2022 17:50:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278644; bh=EPBHgmukQQ2kavRRx6NFY8j/vcnjOWl5lgESjAPm9W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4t7hFXaFvOoLuUOsdcZ2cZ6R001qTr6TsRXR1o+mi9a6rjFrrYg9vkD8wF3zLL2I cTBW1TPqXLxJ5H8EYDRO1dUJEujKeCwCiTa0Ffb2uun531xGrSzfSuHUUkrLBOLMsZ GBr7DsLBNtwgxQkQ8OTYAP7n/60FqOMEytmf59k0= 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.15 47/66] fs/ntfs3: validate BOOT sectors_per_clusters Date: Fri, 3 Jun 2022 19:43:27 +0200 Message-Id: <20220603173822.025720768@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173820.663747061@linuxfoundation.org> References: <20220603173820.663747061@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;