From patchwork Tue Apr 25 13:57:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9698251 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 AE1E560249 for ; Tue, 25 Apr 2017 13:57:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9005F1FFCA for ; Tue, 25 Apr 2017 13:57:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81B3128614; Tue, 25 Apr 2017 13:57:50 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 267D31FFCA for ; Tue, 25 Apr 2017 13:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947745AbdDYN5s (ORCPT ); Tue, 25 Apr 2017 09:57:48 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34891 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1947743AbdDYN5r (ORCPT ); Tue, 25 Apr 2017 09:57:47 -0400 Received: by mail-wr0-f196.google.com with SMTP id g12so7115801wrg.2; Tue, 25 Apr 2017 06:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ug9lKkFoYLMbyZscuaHUdRoXowdUGuLR61pQlv1pJvQ=; b=paEfJeybgJPLEHJvZoh6Rjc5YhSW3I7I2ihqZf/C3fo+oalUSbl+JIqmK30G3/ecdC NZcD29dKonNcjgFtDG7IPTtsR3FI65AGcqMb+7NO3bF/2ZW2bigUQTv7u4ThGzjB257W 9iFFJ/xeZgBlpoFbIbREtsO6ngvpgmHGI6q+MJrVPHBO6/BFARI82YVjhCiP1nCfR5CM z7tRPD2bBzPsgGcimESvCZ11atEMwOBFtHRPMnJAlKvQty5r/P0KM1JESpzkV263OY+B rXFF2vrTHHbdqlRi3De0FYJXS7zp1oFZm5ukYHcVG0MwsPXXhI/0xhQvuI0SRbKh+Vvw hn8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ug9lKkFoYLMbyZscuaHUdRoXowdUGuLR61pQlv1pJvQ=; b=o8AkAQDT1TjFhDifbdu4a0hdnGLU4iW+qvygnOwU5Wa4mG1IzU3ridcPpAhxxa/gf1 rq8rZucz21kOogwvw4T4v88TVPYqxgtky+4Iw+P6yO2J6/SrzJWXYUtDghDwuyAnL8Zz Nl7kSxq6U0GxHsqYXCPa/srPC7DDr23uIx0XUiMzZ2DOtM+mFsGycWzjQL2vW9Gz4qkX LuvYYRUejTCiOOp23Pv4cqxhx37bhJbprnzp/PKlTQICvtKpwdashtzklecO02yAAqS6 cS0Wz26ybachf7TLIq7r/eWuorNJ6X2vjUfyVeUGBn3288lsw8t1YKlVQBrwDfjElBfZ FoKQ== X-Gm-Message-State: AN3rC/7lpjnoFL/utuUtOFBpCuvb97LkyNJ4j8qgaWUcx7Y/5UCN/Ier u/3l6ie1iuGe4Kli X-Received: by 10.223.130.104 with SMTP id 95mr10023168wrb.150.1493128665809; Tue, 25 Apr 2017 06:57:45 -0700 (PDT) Received: from amir-VirtualBox.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id m139sm5065723wmb.27.2017.04.25.06.57.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 06:57:45 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Trond Myklebust , Jeff Layton , "J . Bruce Fields" , Tyler Hicks , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] ovl: don't expose EOPENSTALE to userspace Date: Tue, 25 Apr 2017 16:57:55 +0300 Message-Id: <1493128675-24331-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 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 An overlay dentry holds a lower dentry that may belong to an NFS mount. Overlayfs calls ovl_path_open() to get a file descriptor of a lower file for copying up its data and for a lower directory for listing its content. If that lower dentry gets invalidated after ovl_dentry_revalidate() and before ovl_path_open(), the internal error code 518 (EOPENSTALE), which is not a POSIX error code, will be exposed to the user. Check the internal return value -EOPENSTALE in ovl_path_open(), just the same as it is checked in path_openat() and replace it with the POSIX error code ESTALE. Cc: Signed-off-by: Amir Goldstein --- fs/overlayfs/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) Miklos, Following a similar bug report and a fix I posted for fanotify, I realized that overlayfs can also expose EOPENSTALE to userspace. I did not try to reproduce this with real lower NFS, only tested patch correctness using a debug patch. I guess a reproducer could work with ovl_copy_up_data() that is delayed for a long time without concurrent copy up in kernel <= v4.10 and lower file is pulled underneath while copy up is pending. However, with concurrent copy up in v4.11 that reproducer will be of no use. The only other suspect I found for dentry_open() of an NFS dentry without checking -EOPENSTALE is ecryptfs. David, I think fscache won't be storing it local storage on NFS, right? Added CC stable. Although I am not sure how important this fix is, seems simple enough that breaking POSIX would justify patching stable. Anyway, if you think this calls for a VFS helper I don't mind doing it, I'm just terrible with names so please suggest one. In that case, should we make dentry_open() static? non exportable? Thanks, Amir. diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 89789bc..931d199 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -328,7 +328,11 @@ bool ovl_is_whiteout(struct dentry *dentry) struct file *ovl_path_open(struct path *path, int flags) { - return dentry_open(path, flags | O_NOATIME, current_cred()); + struct file *f = dentry_open(path, flags | O_NOATIME, current_cred()); + + if (unlikely(IS_ERR(f) && PTR_ERR(f) == -EOPENSTALE)) + return ERR_PTR(-ESTALE); + return f; } int ovl_copy_up_start(struct dentry *dentry)