Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1974209rwe; Fri, 2 Sep 2022 06:50:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR5bVaish6Ia/7VqXn8OFJrXdWep8wK50pDvuvrDybKquYAdMs3PggViR7VkqXQoV2urvLI7 X-Received: by 2002:a17:90b:1652:b0:1fd:eca8:d2be with SMTP id il18-20020a17090b165200b001fdeca8d2bemr4993055pjb.79.1662126651265; Fri, 02 Sep 2022 06:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126651; cv=none; d=google.com; s=arc-20160816; b=dlGxkR01BMr9QapYYdE20DJ8N5F6WwJ1/cAEBP5AiZy5DverIKac7YrSsRw9ng/6+X g1x/JSPUaHxOagYdhKizJGBKdMYmsFngdPR2fKoDF2OJSgSEYC2bCbuYeqVqJCjejAW5 RnFn0G2vJ54hPX3i93PafG8yI7XSIlQDf6nPDcJO/nQ0HAmC16gWa57YLnw/DQx3lqIl azd97WY6UgNQsuo13LKZOZJcvt4jTnbXz+CyJJetnHkXUdCF/ORfynsuvrZ6K4v8riJS /1QlJKP1ITxuvDwyLuKB97oe8q5keW9FNlrhf+gWVZSKip9zn2WrNqoFd49ks85uxVA6 gTyw== 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=/UAtsDjLPcq3w6Mn54tWuPkrKZ2Xz5dxzpfC4pzjbBU=; b=bD3dBdj/LmKCbUbSOTbObyUgJ3OWx07ZMDWDkeIhzOXJWdhxURXN4uailqqmu2Wuhj KaRQ1DAFJLF7ksEk70M7++EfyV/Ws3TR9pgPxOuZGbBFmbL/LVHQMcr8F+tB6jWf4OXI lVaOsVTelwN9F0+EWHrpZUePczaDWnQPxa/kOJGZDugdHm823fvElfqi7964WmxS21uE ZC6lmgHORGxaLE99O2bmfdgEthdnIjBh9cEBsbJFrOw5J+zzdEo6+ud96202ackbEQkJ SEVzn18k0/iS5iauYZHncxlY/f9R+Jj89dV+H8ChU6hQh76YCLtibKnRsiau8KWd6U0l 5eEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SikpsFpo; 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 f186-20020a6238c3000000b0052acba35ae1si1920216pfa.135.2022.09.02.06.49.54; Fri, 02 Sep 2022 06:50:51 -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=SikpsFpo; 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 S236195AbiIBMZF (ORCPT + 99 others); Fri, 2 Sep 2022 08:25:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236281AbiIBMYW (ORCPT ); Fri, 2 Sep 2022 08:24:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EB2D418A; Fri, 2 Sep 2022 05:22:33 -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 34886B82A90; Fri, 2 Sep 2022 12:22:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 977A5C433D7; Fri, 2 Sep 2022 12:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121352; bh=FXyEu8HN2IyznEME5orkFpYzDlXIChtKtF2NvCi/nnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SikpsFpo9mCYuYkgpUiPm0MAJoTWAmhbYhGVwuQkVJtTlLl+YmNvL8qsHnP4XIbKe WUFv82G86tAZB0afagBcHY8GC4oS0TK7Ku57vAigua5o2LSXZSbt10lUQY+mhLipeR iv32Q/sL6876UjVF8nRtuxxEqnLbjT6FRbnxwbcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Matthew Wilcox (Oracle)" , Siddh Raman Pant , Christoph Hellwig , Jens Axboe , syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com Subject: [PATCH 4.14 22/42] loop: Check for overflow while configuring loop Date: Fri, 2 Sep 2022 14:18:46 +0200 Message-Id: <20220902121359.572611898@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121358.773776406@linuxfoundation.org> References: <20220902121358.773776406@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: Siddh Raman Pant commit c490a0b5a4f36da3918181a8acdc6991d967c5f3 upstream. The userspace can configure a loop using an ioctl call, wherein a configuration of type loop_config is passed (see lo_ioctl()'s case on line 1550 of drivers/block/loop.c). This proceeds to call loop_configure() which in turn calls loop_set_status_from_info() (see line 1050 of loop.c), passing &config->info which is of type loop_info64*. This function then sets the appropriate values, like the offset. loop_device has lo_offset of type loff_t (see line 52 of loop.c), which is typdef-chained to long long, whereas loop_info64 has lo_offset of type __u64 (see line 56 of include/uapi/linux/loop.h). The function directly copies offset from info to the device as follows (See line 980 of loop.c): lo->lo_offset = info->lo_offset; This results in an overflow, which triggers a warning in iomap_iter() due to a call to iomap_iter_done() which has: WARN_ON_ONCE(iter->iomap.offset > iter->pos); Thus, check for negative value during loop_set_status_from_info(). Bug report: https://syzkaller.appspot.com/bug?id=c620fe14aac810396d3c3edc9ad73848bf69a29e Reported-and-tested-by: syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Reviewed-by: Matthew Wilcox (Oracle) Signed-off-by: Siddh Raman Pant Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20220823160810.181275-1-code@siddh.me Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1212,6 +1212,11 @@ loop_get_status(struct loop_device *lo, info->lo_number = lo->lo_number; info->lo_offset = lo->lo_offset; info->lo_sizelimit = lo->lo_sizelimit; + + /* loff_t vars have been assigned __u64 */ + if (lo->lo_offset < 0 || lo->lo_sizelimit < 0) + return -EOVERFLOW; + info->lo_flags = lo->lo_flags; memcpy(info->lo_file_name, lo->lo_file_name, LO_NAME_SIZE); memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);