From patchwork Tue Nov 15 13:32:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johanna Abrahamsson X-Patchwork-Id: 9429831 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 184286047D for ; Tue, 15 Nov 2016 13:32:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 051F02894E for ; Tue, 15 Nov 2016 13:32:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED49B28A10; Tue, 15 Nov 2016 13:32:30 +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.4 required=2.0 tests=BAYES_00, 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 533A72894E for ; Tue, 15 Nov 2016 13:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754082AbcKONc2 (ORCPT ); Tue, 15 Nov 2016 08:32:28 -0500 Received: from mail-qt0-f194.google.com ([209.85.216.194]:36313 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752754AbcKONc2 (ORCPT ); Tue, 15 Nov 2016 08:32:28 -0500 Received: by mail-qt0-f194.google.com with SMTP id n34so8249636qtb.3 for ; Tue, 15 Nov 2016 05:32:27 -0800 (PST) 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:mime-version :content-disposition:user-agent; bh=7eRJuKYSt1jthA+svyb8tB81fMCvV6QR/zf2jwItKC8=; b=M4y+pgtUXL6u4hvyZU+T/Fx9iQtiv1LLZwv/1QRUdBr/w6mWlthX4vnf6qAuiEwagL Ruhve4qMrbn/zSRnob9ga8JQ3eC+fhrCbI5O1755WQeaJOb8IjXDPvzJnC0VZFjLACtM 4YR1CdR9w3T2GvJgkDRo7ju9yGDyz0dPJAeZvwrN4nf3hJz3LsNOs5r1o7vQpuIuvauo rgfrpMT5pjgcegE9QEZfqeDFUc0utK5TxsNoQfCiSkvp/mHv7/HfRK8oZmXIB3kUoRwp gFgfQTjBAHlHKd7jIpg4hFqeQosXcYVuOO2S/lbba36h/4kOmqFBtV2PUclWB6p3qw2b SV2Q== X-Gm-Message-State: ABUngvepV4okykHcULhjsIb1sxmgIsKcbnvndXKBqhkCxb5KDlWzc+PGIZe7h23XXocFcQ== X-Received: by 10.25.18.167 with SMTP id 39mr10276273lfs.81.1479216746898; Tue, 15 Nov 2016 05:32:26 -0800 (PST) Received: from fedora-21-dvm (c-3decd854.021-235-6762674.cust.bredbandsbolaget.se. [84.216.236.61]) by smtp.gmail.com with ESMTPSA id w67sm6313136lff.16.2016.11.15.05.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2016 05:32:26 -0800 (PST) Date: Tue, 15 Nov 2016 14:32:24 +0100 From: Johanna Abrahamsson To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH] vfs: Allow FS_USERNS_MOUNT filesystems to create inodes with unmapped uid/gids Message-ID: <20161115133221.GA23813@fedora-21-dvm> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) 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 Fixes: 036d523641c6 ("vfs: Don't create inodes with a uid or gid unknown to the vfs") This fixes the bugzilla bug #183461 (https://bugzilla.kernel.org/show_bug.cgi?id=183461) "mkdir(2) returns EOVERFLOW on tmpfs in user namespace" that was introduced in the aforementioned commit. Since filesystems with the FS_USERNS_MOUNT flag (mainly tmpfs in this case) are safe to use within user namespaces they should be allowed to create inodes without checking whether their uid and gid has a mapping or not. I learned most of what I know about user namespaces while researching this bug, so there's a fair chance that I've misunderstood something. Feedback is greatly appreciated. Signed-off-by: Johanna Abrahamsson --- fs/namei.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1669c93d..9e45e01 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2816,10 +2816,12 @@ static inline int may_create(struct inode *dir, struct dentry *child) return -EEXIST; if (IS_DEADDIR(dir)) return -ENOENT; - s_user_ns = dir->i_sb->s_user_ns; - if (!kuid_has_mapping(s_user_ns, current_fsuid()) || - !kgid_has_mapping(s_user_ns, current_fsgid())) - return -EOVERFLOW; + if (!(dir->i_sb->s_type->fs_flags & FS_USERNS_MOUNT)) { + s_user_ns = dir->i_sb->s_user_ns; + if (!kuid_has_mapping(s_user_ns, current_fsuid()) || + !kgid_has_mapping(s_user_ns, current_fsgid())) + return -EOVERFLOW; + } return inode_permission(dir, MAY_WRITE | MAY_EXEC); }