Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3857505rwa; Tue, 23 Aug 2022 11:18:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR7vGRMd+aouit5wIkQLdE0C/CX8xdN0L9HWAPaUq1LfZmTA+KEsiN8BS+i0VzejyrsCG8Vv X-Received: by 2002:a17:907:7e9b:b0:73d:8044:a5f1 with SMTP id qb27-20020a1709077e9b00b0073d8044a5f1mr532419ejc.721.1661278730340; Tue, 23 Aug 2022 11:18:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1661278730; cv=pass; d=google.com; s=arc-20160816; b=CCriLnsGq9yA3CoYWdPqs+yftyni8esrdT+mFik2TL8oFFBCxQcOwHg8vgVVFenUUR ttzRSejBxtExaDyWRhEJdPQ95glI6helAHKDpc8AAH7mLHJWj8rcgeCMsMlVAaAaS2E6 WeEpRSkMQQ7kfQDRzxswWyvKcy/4caLGrL0Ky3OYE8OfWcRb8dF7DWEfC1otF8wNHvUT z+bpc4KW/Go2tz4+0vNwMLwQoBq/KmlQf9IG96bDiZa4F69lxbjigUQeKJysIuc2+RBa +SOt/g6eyaSQySkDOaCUgto9YZUuylgJ0DvGMjrxF4wkBzlWmGwVty05oidXg36fw7EO OZjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:message-id:cc:to:from:dkim-signature; bh=UjlKgz2xV4xjj14J2LSVuB5e7dOd3HlE+vr/w0QgVZY=; b=V34zvVJy5PVAodo4oe3FO6VA/7bMXzKcduFwID0rWK3Z9HDCgSNw8ZeEGDRXQyejwE k1WuffilwnMbDJwUy1CnVulQHZbUnPeXW2sjljiS6jAsXgtX+afJN8ROFXiaXqqf8d55 AxWHZ5HHKtOJ2qqWqGwzU5znuZvUSuOP5q3LL1KWTVF8XHZvDFulsRV8L4yHejjfaqMS EppwZgaJgA3MMDlgDPvdbxVef64PDlvKH0FJnJaVTtFFjvc4x82J7Lq9vuBEabE+DQeZ 5gDjnxlUsl9UIICUo59lqH5D8b89s794VnMp5yxMZ4L+3QF9vUE+0/b8b7wn7evjWiNg faPA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=eDrovX6M; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a05640234d400b0044718451195si2531612edc.175.2022.08.23.11.18.24; Tue, 23 Aug 2022 11:18:50 -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=@siddh.me header.s=zmail header.b=eDrovX6M; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233802AbiHWSDP (ORCPT + 99 others); Tue, 23 Aug 2022 14:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbiHWSCk (ORCPT ); Tue, 23 Aug 2022 14:02:40 -0400 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCB599273; Tue, 23 Aug 2022 09:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661270904; cv=none; d=zohomail.in; s=zohoarc; b=JVbN+o5FIkISrOPZjQPBvu7OtJzN5G0kKXh7ZPoAz8eC9NXnhSBCwprJ6TF2X4asewUz/yenEjwIgIiPvLrA7h+gta3HpdyFjm/it43ikI5+9wNwfLVLviOJtDC/xGXV3bGjlXRUCujm9SpOVaq3drWXLZSvwhqoBBU0fy27ePc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1661270904; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=UjlKgz2xV4xjj14J2LSVuB5e7dOd3HlE+vr/w0QgVZY=; b=WHiautuSleOVUZ1HN15b6q2eN4Ww7jAUeZeBaFmfgFha3QC3VZ6/scZ9Y+VW9vjc15EGDVqhfCgOuZYGfcUweOcwWB1Laku9NzJ16nPd7k1BqQTnK0vz3vfyxlfwNGFC2fUoieItEf4hb8xUopcSr2i23hzmLIx/hKUAF0ayeHM= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1661270904; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=UjlKgz2xV4xjj14J2LSVuB5e7dOd3HlE+vr/w0QgVZY=; b=eDrovX6Mi9EX6AYter3SwakhVr0/cg9vJe4zqQeZYHzPotfHPdliEIV8aT8Se/om GZaiYUGXu4AGTvESCJVUbDwa7nMZ8K0o3KIYLKZH2E7DHzPqBwzC3mWJLwKRd+HzdZE 66aJYjlRmyaZHmfJ5MDJQfYAxHlUy5MvydthSLG0= Received: from localhost.localdomain (103.249.234.81 [103.249.234.81]) by mx.zoho.in with SMTPS id 166127090391618.64430756700915; Tue, 23 Aug 2022 21:38:23 +0530 (IST) From: Siddh Raman Pant To: Jens Axboe Cc: Matthew Wilcox , Christoph Hellwig , linux-block , linux-kernel , linux-kernel-mentees , syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com, stable@vger.kernel.org Message-ID: <20220823160810.181275-1-code@siddh.me> Subject: [PATCH v2] loop: Check for overflow while configuring loop Date: Tue, 23 Aug 2022 21:38:10 +0530 X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_RED 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 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): =09lo->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: =09WARN_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 --- Changes since v1: - Do not break userspace API, so check loop_device for overflow. - Use EOVERFLOW instead of EINVAL. drivers/block/loop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index e3c0ba93c1a3..ad92192c7d61 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -979,6 +979,11 @@ loop_set_status_from_info(struct loop_device *lo, =20 =09lo->lo_offset =3D info->lo_offset; =09lo->lo_sizelimit =3D info->lo_sizelimit; + +=09/* loff_t vars have been assigned __u64 */ +=09if (lo->lo_offset < 0 || lo->lo_sizelimit < 0) +=09=09return -EOVERFLOW; + =09memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); =09lo->lo_file_name[LO_NAME_SIZE-1] =3D 0; =09lo->lo_flags =3D info->lo_flags; --=20 2.35.1