Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3091458rwe; Mon, 29 Aug 2022 05:49:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6cZ3ztdPolwn0plNXjM/Lo5XIHg9WnAvswilkfW9IlOuTLrQ6b8NDKEHCILcHCofCVMDk8 X-Received: by 2002:a17:902:8ec6:b0:172:dc2c:306d with SMTP id x6-20020a1709028ec600b00172dc2c306dmr16723102plo.104.1661777348518; Mon, 29 Aug 2022 05:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661777348; cv=none; d=google.com; s=arc-20160816; b=WWBRvyRm/Q1mYU3viQfcf3IVLWTw2HU6L14IItTgX6RwNKW8CKL/GMDlQqNpYc7N0E cvby2xQa0Q0CzN8fowXodT03kMTtpmQBag/xNSQ4E/sQn8kO5TE5reIN3JZqWewmibgq Vnyk5wh6S17dQYh+F7VsWF7Decb0yTFDEZNVo7zgcuV5hwyKOWiRRguVYSaiDzvCeLlf YtE9fnqfydljWvphnRRsJAS3x5qiYzz+ooQySciGSVnPSFw4sBXmrBsCqewYBb5dr+ag SPD2FTrXZ988h6rg8TO0G9yZ5ZrViemHVqySPmGlHQ7xFNGi9X8MPNilTyuzKiYIpVSG /Ewg== 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=z+EyHCPuId7+1iTIiq/scz/RdF0xTh80PHs0e0Zvbg0=; b=AKU380JM9/ETVfLGIXU/aHruoWE/MxUVv8/VrIR/kpToqHwyiXANiMkUwl2AMzKQpY En1BA6Fus7gGQNaKgjMGHPwKYv7O8i5qgvkZc0SYbhqjNasfOv22FrrnEO8SzL2c/DFY svMwRQI00mrQFMXNF5FBX4ovS9CEoBepUyeaUtPe2oyC39+NUXp/2+GaJqXxAeMua/v4 8zVhe1kKQVpzYloaCeBXQZJZbmaN68pu3eG/2p+L0sqae9TCyv3XsSqPunvm5QbPcCPT NDG4W863ZeQcgOtOATYofuJ6fjmM2ZR+3mlPDx/J/YO+qBCV5k3dWuCXNqqT75t6IoHT 15Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ch3D2fLu; 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 oa10-20020a17090b1bca00b001f74f8ee43asi10094009pjb.25.2022.08.29.05.48.56; Mon, 29 Aug 2022 05:49:08 -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=Ch3D2fLu; 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 S229751AbiH2MmL (ORCPT + 99 others); Mon, 29 Aug 2022 08:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiH2Mlr (ORCPT ); Mon, 29 Aug 2022 08:41:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A00A475; Mon, 29 Aug 2022 05:26: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 9E07461221; Mon, 29 Aug 2022 11:11:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93248C433C1; Mon, 29 Aug 2022 11:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771477; bh=YsXn6jJWmPbxql1irJ9ABDMr3QJ9zrouKG/JnRumW7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ch3D2fLuzUi7lvroN6022X9LpWa87U2VsHUes0LrXBl4Q8xWcEy9V+RvljogRUCw+ kqg00YjeTgaZ2XW7mWaz0nkWZ82QqhGwUky1qg5WmN1DutokSTPzOHIVlhH8dNlr+M k4cieYL1M/vHR7oJhS1G0Xx6Sexp9KuZMJlUSPEM= 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 5.10 71/86] loop: Check for overflow while configuring loop Date: Mon, 29 Aug 2022 12:59:37 +0200 Message-Id: <20220829105759.451337362@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@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 @@ -1031,6 +1031,11 @@ loop_set_status_from_info(struct loop_de lo->lo_offset = info->lo_offset; lo->lo_sizelimit = info->lo_sizelimit; + + /* loff_t vars have been assigned __u64 */ + if (lo->lo_offset < 0 || lo->lo_sizelimit < 0) + return -EOVERFLOW; + memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE); lo->lo_file_name[LO_NAME_SIZE-1] = 0;