From nobody Sun Sep 7 12:25:50 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADBD3ECAAD5 for ; Fri, 2 Sep 2022 12:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237207AbiIBMki (ORCPT ); Fri, 2 Sep 2022 08:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237176AbiIBMim (ORCPT ); Fri, 2 Sep 2022 08:38:42 -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 2FED250063; Fri, 2 Sep 2022 05:30:23 -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 A4A00B82AA1; Fri, 2 Sep 2022 12:28:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0432DC433C1; Fri, 2 Sep 2022 12:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121714; bh=WyLP5ydkN6YSnIDeflr0Opmd73Mf9jckl4YO+rrhNWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ReEw3j/c+ZjjcFWWHHLPPhuOn4+JHFMCFZUADtOzXB3l4uHErzWtXMuc7/2hrqCz1 yWf8bagSXpTXEI+4AKAeybz2ANrSEZRTJBoSWObmYEPXsZnbLFnmj3SKCuec1Nyx4e UjhJL+hW9e1R+b+EpJS+Iugmi567sOrKeDRJtWx4= 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.4 41/77] loop: Check for overflow while configuring loop Date: Fri, 2 Sep 2022 14:18:50 +0200 Message-Id: <20220902121405.014969652@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121403.569927325@linuxfoundation.org> References: <20220902121403.569927325@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D 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=3Dc620fe14aac810396d3c3edc= 9ad73848bf69a29e Reported-and-tested-by: syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.c= om 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 @@ -1397,6 +1397,11 @@ loop_get_status(struct loop_device *lo, info->lo_number =3D lo->lo_number; info->lo_offset =3D lo->lo_offset; info->lo_sizelimit =3D lo->lo_sizelimit; + + /* loff_t vars have been assigned __u64 */ + if (lo->lo_offset < 0 || lo->lo_sizelimit < 0) + return -EOVERFLOW; + info->lo_flags =3D 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);