From patchwork Wed Jun 29 14:03:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9205343 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 EFDBD607D8 for ; Wed, 29 Jun 2016 14:04:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E171A2865B for ; Wed, 29 Jun 2016 14:04:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5E9B28662; Wed, 29 Jun 2016 14:04:00 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 3B94C28665 for ; Wed, 29 Jun 2016 14:03:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752913AbcF2ODc (ORCPT ); Wed, 29 Jun 2016 10:03:32 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33626 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752540AbcF2OD2 (ORCPT ); Wed, 29 Jun 2016 10:03:28 -0400 Received: by mail-wm0-f66.google.com with SMTP id r201so14619394wme.0 for ; Wed, 29 Jun 2016 07:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=iizM3UaaGUHqsNVv2MvRZR9q0cXIkGMg/xz718Cd9cs=; b=WwCH2Tme0KP5CWnDbpp+EbSqW6Fhl8yYwut0I0r8LzsfQgwO12DF+Hy6aN4YTvoE1T kQbnpY5Ff5ZYge4oT+tIHrKhXAZULLEnwHjfjHhZr0KBMUV6s8M8xPXLBmSF3ZzsPXgF 8ugToOzUiSRANMpdc1aIKBsJevYIK2y3rdgoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=iizM3UaaGUHqsNVv2MvRZR9q0cXIkGMg/xz718Cd9cs=; b=IX7pRP4gS60JjfNbm3tw8eBrkV9LAIYh2NKHoJaQfVgEAbBKuAn1Gat1aClY6rOJKC BW4jQCJ1wYdqJM0VDAJh3vnOs7RyUR+D4L0qYh3baeu+A3/dUeYLP7A/KDAiBY6PT9iK BhSS/p5w0R19Fvv6n79Mi9/jMDf48KSDOTncI3LoXl9wvHH07tHruw42hwPVQ760NR6W 4Q5AejGVHCpXh5LSTyvC9zASihFsvxM0aUJ8GTKwFeI9zVwLuWcBMGrFcqNpuYWY8bpX AlHEj5r6fd7ij6oDGuLbHTHE5kO3NaCRKlfBaAcrs8lcrYk7D+0DGkwIKHyrFHn3ZOxx AT+Q== X-Gm-Message-State: ALyK8tJEkzsbMNyDIeHNW/0Q+67DyJ6fwAHBp2dSrbZubx+qv4VCKWD3G4d7aXaDPn+20Q== X-Received: by 10.28.109.137 with SMTP id b9mr21442411wmi.68.1467209006582; Wed, 29 Jun 2016 07:03:26 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id ur2sm3876660wjc.33.2016.06.29.07.03.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jun 2016 07:03:25 -0700 (PDT) Date: Wed, 29 Jun 2016 16:03:18 +0200 From: Miklos Szeredi To: Zhang AiHua Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org Subject: Re: =?utf-8?B?cmV0cnnvvJpbUEFUQ0hdIGZpeCBl?= =?utf-8?Q?rror?= =?utf-8?Q?=3A?= a bin file can truncate itself while running on overlayfs Message-ID: <20160629140318.GA3936@veci.piliscsaba.szeredi.hu> References: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> <57707C2E.2080500@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <57707C2E.2080500@huawei.com> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, Thanks for the report and the testcase. Here's a patch using a different approach (overlayfs philosophy is to minimize VFS footprint). Thanks, Miklos --- From: Miklos Szeredi Subject: ovl: get_write_access() in truncate When truncating a file we should check write access on the underlying inode. And we should do so on the lower file as well (before copy-up) for consistency. Original patch and test case by Aihua Zhang. - - >o >o - - test.c - - >o >o - - #include #include #include int main(int argc, char *argv[]) { int ret; ret = truncate(argv[0], 4096); if (ret != -1) { fprintf(stderr, "truncate(argv[0]) should have failed\n"); return 1; } if (errno != ETXTBSY) { perror("truncate(argv[0])"); return 1; } return 0; } - - >o >o - - >o >o - - >o >o - - Reported-by: Aihua Zhang Signed-off-by: Miklos Szeredi Cc: --- fs/overlayfs/inode.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -59,16 +59,37 @@ int ovl_setattr(struct dentry *dentry, s if (err) goto out; + if (attr->ia_valid & ATTR_SIZE) { + struct inode *realinode = d_inode(ovl_dentry_real(dentry)); + + err = -ETXTBSY; + if (atomic_read(&realinode->i_writecount) < 0) + goto out_drop_write; + } + err = ovl_copy_up(dentry); if (!err) { + struct inode *winode = NULL; + upperdentry = ovl_dentry_upper(dentry); + if (attr->ia_valid & ATTR_SIZE) { + winode = d_inode(upperdentry); + err = get_write_access(winode); + if (err) + goto out_drop_write; + } + inode_lock(upperdentry->d_inode); err = notify_change(upperdentry, attr, NULL); if (!err) ovl_copyattr(upperdentry->d_inode, dentry->d_inode); inode_unlock(upperdentry->d_inode); + + if (winode) + put_write_access(winode); } +out_drop_write: ovl_drop_write(dentry); out: return err;