Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3055650rwe; Mon, 29 Aug 2022 05:14:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR75pAshXwuNRSpsbYrgW8MIWUvIxg7vNISTLRMkecyntbXZr/ekQP6ks2tlWbDN0Uw9Gz/s X-Received: by 2002:a50:a41d:0:b0:447:e4a3:ca32 with SMTP id u29-20020a50a41d000000b00447e4a3ca32mr12184153edb.122.1661775241349; Mon, 29 Aug 2022 05:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775241; cv=none; d=google.com; s=arc-20160816; b=U+iX5g4q3qx7f+8lPtd7jaE/Ogsq86lJ87LsU2KYpBCElGyqmMgJs+MzU7nWvoeyRb rOZEngtQ9Pzk36wLrTpemPdcIvId3/S3GbiuLo7z2I/EjjQLEUD5qOBvFAiXGMExvG1X 3DqfwvglW/vNBBQs6IFiy8MUX2kOdd01dHln+EZ51eIydnwSM1O5ztE7VnsTZ97QSm31 NyRnzBXbbqfplCGL3cPNdIYbnT19s0zJ20jB8g5vt+g7xIsgs2qYTnatjFxLHqgnLqff CU4sN607vYcnWwQX+TcNoRNu4Ny5yjVZvOnAr0kIT0lvQqSg8FjnnCv31gYEAxnf9XVX Otzg== 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=8qmQRAvGJhyBIp4wCT0HMe6reuEzySAf8L6I+1AT1MM=; b=O2HKV3otXhCmu0pZAz26yhsDDLs3FNPoGVbhlNPv1tjHskhyhtos1InsbFeMYYdw1k vAgFF23kEWP1t8ZUov0+FtTufxlio+3hMCflq3t/U0rLaPB/O5tDvpiMtnllMOqTdA38 EzleL0LzIPRD4iy7k687DbkXjSiTB70WtLe4MYxICsepq6t2YsKcHCmBtMyzKBQcfaPO RwK2Y+bl4PsJ8+2B95ZGDCrBLRSLsE3JZ2402+KrpFntvcFdaVMQDUo5tuVm3ViMtJjC T77lACeHkftm9YBhjtXFpz12bg32Li2MioTPHlt9ltEPDyTQ3fxR3bJXUIcIHb8K5ixY rmTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ljTlipDp; 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 e12-20020a056402190c00b00445f21c2b32si8256484edz.132.2022.08.29.05.13.35; Mon, 29 Aug 2022 05:14:01 -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=ljTlipDp; 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 S232240AbiH2LgJ (ORCPT + 99 others); Mon, 29 Aug 2022 07:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233068AbiH2Le1 (ORCPT ); Mon, 29 Aug 2022 07:34:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB509101E9; Mon, 29 Aug 2022 04:20:28 -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 57415B80F92; Mon, 29 Aug 2022 11:17:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAF29C433D6; Mon, 29 Aug 2022 11:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771830; bh=OO0la5LJzIAMzZqhWPOrFSwER2Kaqw02nahsFFOjM/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ljTlipDpfpBUK0q3p+SGt1fjjMwa5Pes9NReL6ue1BWi2TKfVXDKPCQRwDltTuY+p /tSjs00zza8chdLOxcCK2gtPcQgbse4ub/n6MtHZLQMmk0KZ2D+qoVro8R53tCs7l0 tM1X2Yu18BvEqmIQ3jx0T2+T/XxHorG+fTXHB/sk= 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.19 110/158] loop: Check for overflow while configuring loop Date: Mon, 29 Aug 2022 12:59:20 +0200 Message-Id: <20220829105813.721388114@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 @@ -979,6 +979,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); lo->lo_file_name[LO_NAME_SIZE-1] = 0; lo->lo_flags = info->lo_flags;