From patchwork Wed May 16 17:32:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10404485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DE6F2602C2 for ; Wed, 16 May 2018 17:32:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD6E9285C8 for ; Wed, 16 May 2018 17:32:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1CBC285CB; Wed, 16 May 2018 17:32:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D3C7285C8 for ; Wed, 16 May 2018 17:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751916AbeEPRc4 (ORCPT ); Wed, 16 May 2018 13:32:56 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:41595 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751893AbeEPRcy (ORCPT ); Wed, 16 May 2018 13:32:54 -0400 Received: by mail-pg0-f65.google.com with SMTP id w4-v6so582360pgq.8 for ; Wed, 16 May 2018 10:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pB7CZhC+Ct1pF86bsC78qnYy0dcgL1P0lXM9eWWFLSI=; b=zWDdAJv3uT8RByONM2Pq3RxjfUtGBKCV9GtIYtMZlm3RsqC71CoDFLXDJgrsLZx2sf 4IjwqGTS+uXj/25tsAtG1fnhnsM1RxivPINbbSwi5KzQIg57nNJQdSltTs+ABXD27M82 BnvWZGlukS8s/GUoVMa0k5kSsNpjlV05gOlfaF49CKm6t0e00UYRFf17MIQIgmsBs+WC 1iuEu6sMZh1uRrQDsFbrmXOno1wkwYWGL1lxKKtiXRLLm+TI67a33D5X7kd2VzxpHbQY TJiYkCvNgdFC7jabci48bdJieMULCAzIFjCn7EGc1V+j6zgC98DIrw66bODEAlvoC9AW Mwzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pB7CZhC+Ct1pF86bsC78qnYy0dcgL1P0lXM9eWWFLSI=; b=LELT9Lv/m4sYylhtJzC5O/O3pK58KCeTPD4QomA0b5wAtb4YuV2xk6gWQ3b34H/FEB X9mAfHbVyhqqpbjEXmr8RDy08ZVzPNfESp4gaj0KJUWVc0pKBpJzz6jejbjntagajNuY BWR6ro4Ul8RgAYg2pCQbgzhVtCYQvPGM7IaucofHZFCGueAmJT9GdsYk0vKtzd3Z0aVl Dq24JIuHPNFCktNSkhS8JCi9mpEcPgRwX9dSgKCrHH8w3zKsAczah8a55eEVj7NaSHVS nOWZ3V/oGr+teMim/znT0lTRjqTR2YWd7YXqUZmuvn/wryE9C66jwcITuUM0esgROZp/ FsvQ== X-Gm-Message-State: ALKqPwebPJ0igoroug7NZ+Xn0QHnFUMBFk++0FFOw8DAQexbq6ZRnNOp /AvA6DTNTqlKLtt2HQTHB7PXUw== X-Google-Smtp-Source: AB8JxZq0/Z0qdl+52Zr5oCICn+NaTiqELo3wuW3D+ugsPnBfdA5ips/jBerxXzc4aV9ONnteD8/EYw== X-Received: by 2002:a62:a315:: with SMTP id s21-v6mr1889822pfe.168.1526491973355; Wed, 16 May 2018 10:32:53 -0700 (PDT) Received: from vader ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id m72-v6sm6356275pfk.110.2018.05.16.10.32.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 10:32:52 -0700 (PDT) Date: Wed, 16 May 2018 10:32:51 -0700 From: Omar Sandoval To: Christoph Hellwig Cc: "Darrick J . Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jan Kara , Aleksei Besogonov , kernel-team@fb.com Subject: Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files Message-ID: <20180516173251.GA29231@vader> References: <9faf09627cfa469437b76edb73ac7cc822dc33c8.1526488995.git.osandov@fb.com> <20180516172531.GA13464@infradead.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180516172531.GA13464@infradead.org> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, May 16, 2018 at 10:25:31AM -0700, Christoph Hellwig wrote: > On Wed, May 16, 2018 at 09:45:50AM -0700, Omar Sandoval wrote: > > + if ((iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) || > > + iomap->addr == IOMAP_NULL_ADDR) { > > + pr_err("swapon: file has unallocated extents\n"); > > + return -EINVAL; > > + } > > The two are really different cases - IOMAP_NULL_ADDR shouldn't really > happen for any of the above. Although we might have to move the > inline check before the type check above for the message to make sense. > > I have a patch in the local queue that makes inline a type instead of > a flag, btw as it really isn't a flag. So something like this, moving the inline check and removing the hole check since that doesn't make sense for mapped or unwritten? Then the inline flag check can be converted to a type check. --- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/iomap.c b/fs/iomap.c index d193390a1c20..89517442e296 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1214,26 +1214,37 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, struct iomap_swapfile_info *isi = data; int error; + /* No inline data. */ + if (iomap->flags & IOMAP_F_DATA_INLINE) { + pr_err("swapon: file is inline\n"); + return -EINVAL; + } + /* Skip holes. */ if (iomap->type == IOMAP_HOLE) goto out; - /* Only one bdev per swap file. */ - if (iomap->bdev != isi->sis->bdev) - goto err; - /* Only real or unwritten extents. */ - if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) - goto err; + if (iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) { + pr_err("swapon: file has unallocated extents\n"); + return -EINVAL; + } - /* No uncommitted metadata or shared blocks or inline data. */ - if (iomap->flags & (IOMAP_F_DIRTY | IOMAP_F_SHARED | - IOMAP_F_DATA_INLINE)) - goto err; + /* No uncommitted metadata or shared blocks. */ + if (iomap->flags & IOMAP_F_DIRTY) { + pr_err("swapon: file is not committed\n"); + return -EINVAL; + } + if (iomap->flags & IOMAP_F_SHARED) { + pr_err("swapon: file has shared extents\n"); + return -EINVAL; + } - /* No null physical addresses. */ - if (iomap->addr == IOMAP_NULL_ADDR) - goto err; + /* Only one bdev per swap file. */ + if (iomap->bdev != isi->sis->bdev) { + pr_err("swapon: file is on multiple devices\n"); + return -EINVAL; + } if (isi->iomap.length == 0) { /* No accumulated extent, so just store it. */ @@ -1250,9 +1261,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, } out: return count; -err: - pr_err("swapon: file cannot be used for swap\n"); - return -EINVAL; } /*