Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp899029imm; Wed, 22 Aug 2018 14:46:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYbD2r31xVHQkFLEjbZghyui4CSJDEQLmRCH38ETYMGDNsbJQ20nybFbD6RWB9t+PeQJ6jw X-Received: by 2002:a63:d002:: with SMTP id z2-v6mr1240981pgf.262.1534974393150; Wed, 22 Aug 2018 14:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534974393; cv=none; d=google.com; s=arc-20160816; b=gN6zjtWelo3HFtbprUJdTfq28mwjU2i9v1nvWu3Gdpn8ruao2bMvtpMR6tMZ9Q0jcd X6G3yqRm0ps/Cc1EI9HEaxQTMljnAMAjR2T72jjX9iCJ46o6igNQ26pGgNdmJKwzk8/C IvmyTO++VLq35Y0JwBLvpdu2+ZlWwVV85dcIezvDxyg8DworVsRwROfbFHp8o0Y2P/dz HCHgb2tzVXPwwVe9HQeL1e8MeDs6Ai4m2Tcwat5CxDqie1T5JNVnVKTML8xUNidI80sF 16nVVxGIq3uCSou80K5F8Cbdnwjoy8cmJiNrWY9qHIVVetZAF5hA4IyFpQrd93B3rlwp Yitg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=o7goUdy52b31xooWr7JLCI/IS47yMb50jhfDjw32+Po=; b=s8kTf7g7+elbRn5nf0ni4DQs4mW10AihPTVYcwGnji7l5m8J1XDVZb3ULMsQle8axi UaC/+adDhpx3GwEHzPy3C18ZcD5P+cM0BZLN95XKW8DKTEMRZN1dbevyTEVOU35fnN63 CwevwFMChuN9iw9GQJQ2tHJmEDRrfAGjRF0liWXQLIsxlhRS/d32D8eppvz3WdAXGcNT 34dF/Y327Po5NA4Btuccy2Q09HlYmSvJVVXQzGuTGSc3p3dOxdWqgJKv+DrHL0qPswGz NBJagYY3U7cKqKU9RwZsyH3K7xADrRSGvTWm2waIBnEl1jeG+Mc+3zv2nzz6Rkc8jdDU l82Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4-v6si1540149pga.646.2018.08.22.14.46.18; Wed, 22 Aug 2018 14:46:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbeHWBKW (ORCPT + 99 others); Wed, 22 Aug 2018 21:10:22 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:55769 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbeHWBKW (ORCPT ); Wed, 22 Aug 2018 21:10:22 -0400 Received: from [148.252.241.226] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1fsauk-0003A9-TY; Wed, 22 Aug 2018 22:43:43 +0100 Message-ID: <1534974222.2902.15.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 40/43] loop: add recursion validation to LOOP_CHANGE_FD From: Ben Hutchings To: Theodore Tso , Jens Axboe Cc: Greg Kroah-Hartman , LKML , stable@vger.kernel.org Date: Wed, 22 Aug 2018 22:43:42 +0100 In-Reply-To: <20180716073516.296730239@linuxfoundation.org> References: <20180716073511.796555857@linuxfoundation.org> <20180716073516.296730239@linuxfoundation.org> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-07-16 at 09:36 +0200, Greg Kroah-Hartman wrote: > 4.4-stable review patch.  If anyone has any objections, please let me know. > > ------------------ > > From: Theodore Ts'o > > commit d2ac838e4cd7e5e9891ecc094d626734b0245c99 upstream. > > Refactor the validation code used in LOOP_SET_FD so it is also used in > LOOP_CHANGE_FD.  Otherwise it is possible to construct a set of loop > devices that all refer to each other.  This can lead to a infinite > loop in starting with "while (is_loop_device(f)) .." in loop_set_fd(). > > Fix this by refactoring out the validation code and using it for > LOOP_CHANGE_FD as well as LOOP_SET_FD. [...] > +static int loop_validate_file(struct file *file, struct block_device *bdev) > +{ > + struct inode *inode = file->f_mapping->host; > + struct file *f = file; > + > + /* Avoid recursion */ > + while (is_loop_device(f)) { > + struct loop_device *l; > + > + if (f->f_mapping->host->i_bdev == bdev) > + return -EBADF; > + > + l = f->f_mapping->host->i_bdev->bd_disk->private_data; > + if (l->lo_state == Lo_unbound) { > + return -EINVAL; > + } > + f = l->lo_backing_file; This looks racy; I don't see anything that prevents a lower loop device from being reconfigured while this walks down the device stack. (But this isn't a new problem.) Ben. > + } > + if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)) > + return -EINVAL; > + return 0; > +} [...] -- Ben Hutchings, Software Developer   Codethink Ltd https://www.codethink.co.uk/ Dale House, 35 Dale Street Manchester, M1 2HF, United Kingdom