Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3472087rwa; Tue, 23 Aug 2022 05:26:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR5BtomdQeO1hCuckyaMeIhcUKXxd55J67Blw0Xg5KFmS4aXw55Sgt0OFElFRY108zkPm0f3 X-Received: by 2002:a17:902:e809:b0:172:eded:e879 with SMTP id u9-20020a170902e80900b00172edede879mr8268032plg.54.1661257527427; Tue, 23 Aug 2022 05:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257527; cv=none; d=google.com; s=arc-20160816; b=Dz8mPBrGY+gGd2TGujdSZaaGw7AiXgb91Lo9V22Jh9kjKXtmBhesZRZL9ENJ/ielSQ cuAQMDGB7Klxp9sEWgj8qnazzQWfUo/MfnHzbirKujkOp1xp6tHANuSkIP+PxgChKQKs Uv3bmuwdth4wZLKh5xiUh3XU7m/5My5wIr8M/HSgYFhE1N+C2/YkBLtrP0AafqheUS/5 nBBoD5yst/KVky5bPpZgzoMA3JVxvls0qLWntrFWAQ0KF9u2/y2mQCIF3ozK0afndDsL bUDsfckEBIu1m7TGzReDetU1qCaWl0AVLqQo53Zj2deqcPQJJx319MM5cqJS4UFT/Xwd EnQQ== 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=9mMFw5a2EGDlNJ5PxGDWHHv39/BCC1K/a1FjWPyNIyA=; b=ykotZJnzJ+ptOruSYNA7H1JpEaJgd41aPHEGLoLkaBAHZxJoWsKiVf1+4D7VGWkDjg oMiejKIiHggLNC/Lp4/Ial1+EpG5lGnVZpi1ZUQtK9CHALrhbXhckRtmlT0SlRlFfQu2 utMGjy+YxTUBIVattuN6k/P2t3rZ4HeLCubP/vOSOyQNrNIQukzNBzHPKQVBhfILaC0J sYOUU7JmqG2XiRTjKyOhrMgHPm9P36jlhJr9QyWnE88cZVsPjUpN90Gwbg0dWZtHrLxs nngDau9n63BDshCFMF9t5QXb/GLEk/A2rJrJVmW6CtSVV4KARxBAkSvwOTpJRDaJwtCz qLEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T4fN/Gcm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a63fe09000000b004129a78936fsi16356723pgh.1.2022.08.23.05.25.15; Tue, 23 Aug 2022 05:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="T4fN/Gcm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354958AbiHWKaX (ORCPT + 99 others); Tue, 23 Aug 2022 06:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353299AbiHWKON (ORCPT ); Tue, 23 Aug 2022 06:14:13 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE54972FE6; Tue, 23 Aug 2022 01:59:54 -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 sin.source.kernel.org (Postfix) with ESMTPS id 3F24CCE1B2C; Tue, 23 Aug 2022 08:59:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F40CC433D6; Tue, 23 Aug 2022 08:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245191; bh=nJdKeWgqbwSrC1zoMSnCLvplncVpAtSgrQGy4V7rxN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4fN/GcmafdOrofZIY+h4OaBD3K3xRQl0a/hAVw24golU+X5LbXw9ok76wbpPYi+h HxOMJLus1rwqkbrd0hQjeXce6LhHL45hqeD0USRn9sbSAw/u87YKwdfDVf8zpHuYs9 Aar56weC+gO9Wkyc6wP2BKffv3nzsTVCl0ApDDZM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "Darrick J. Wong" , Allison Henderson , Catherine Hoang , Leah Rumancik Subject: [PATCH 5.15 244/244] xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* Date: Tue, 23 Aug 2022 10:26:43 +0200 Message-Id: <20220823080107.796989859@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: "Darrick J. Wong" [ Upstream commit 29d650f7e3ab55283b89c9f5883d0c256ce478b5 ] Syzbot tripped over the following complaint from the kernel: WARNING: CPU: 2 PID: 15402 at mm/util.c:597 kvmalloc_node+0x11e/0x125 mm/util.c:597 While trying to run XFS_IOC_GETBMAP against the following structure: struct getbmap fubar = { .bmv_count = 0x22dae649, }; Obviously, this is a crazy huge value since the next thing that the ioctl would do is allocate 37GB of memory. This is enough to make kvmalloc mad, but isn't large enough to trip the validation functions. In other words, I'm fussing with checks that were **already sufficient** because that's easier than dealing with 644 internal bug reports. Yes, that's right, six hundred and forty-four. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Catherine Hoang Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1545,7 +1545,7 @@ xfs_ioc_getbmap( if (bmx.bmv_count < 2) return -EINVAL; - if (bmx.bmv_count > ULONG_MAX / recsize) + if (bmx.bmv_count >= INT_MAX / recsize) return -ENOMEM; buf = kvzalloc(bmx.bmv_count * sizeof(*buf), GFP_KERNEL);