From patchwork Tue May 5 09:59:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC3D81668 for ; Tue, 5 May 2020 09:59:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B50CE206B9 for ; Tue, 5 May 2020 09:59:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NN7YhVSx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728704AbgEEJ73 (ORCPT ); Tue, 5 May 2020 05:59:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24784 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728677AbgEEJ7Y (ORCPT ); Tue, 5 May 2020 05:59:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zXA4w7SFuvdgtElQZS4nWZuP6eglSGx7ZZVh8H1aUkI=; b=NN7YhVSxArdUFq0ke6ODbPFO78T+kyH9VNLhM7SH43EU2HNvw3FoelrQNAw9h99LS2SoB1 89hFs4CMd/hQcpif2vuz34C7qkXYSqJrGRAHqYsDVXWoqv3KVn7dkB2QbxpnQfOqR4/xOq yy5qkslmXNu9swxtHyknbNhEE6wmGpc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-gTGbV3rhM--ZbfCGmKYCww-1; Tue, 05 May 2020 05:59:20 -0400 X-MC-Unique: gTGbV3rhM--ZbfCGmKYCww-1 Received: by mail-wr1-f72.google.com with SMTP id y4so975794wrt.4 for ; Tue, 05 May 2020 02:59:20 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=zXA4w7SFuvdgtElQZS4nWZuP6eglSGx7ZZVh8H1aUkI=; b=cgfnWQ5MS9G+yMRhUJkd9c+owndsQB/CXySwUbTqgfG7b+gH6Z6dfeZE5YCKGwzMUx E7Zjy7YPmC8dBrOBPwYru01J8htIkyV+L0GGz6HT55NOAVEZ4DNB9OpZ20p3OqKsZhX7 9mFob8ETxsLhdC806THJKG/Ghz5tivijrQ5pU56Yu+OeBJMPTx7LDPprErLIf1Y8k4M6 CWsgyjM/Yv2NWO2RfvfRjQ/l5pjs1j01mgkSFfx9mLfe2LpQuYg/BuSTu4MC4J6AeG0F P+ck2mSdkzQ7VL5Mpamo4HTB1f5KRhwW7t7agrR46Z2/ah9NzP1G1NdIHZDsmNJujY43 /65Q== X-Gm-Message-State: AGi0PubQucC26MzZ5xVhiJ821w8+I5xTt6RXzJu08EtMNv1F4sr3v8go HxHLfkUuAUV1pJEOTkZdos6s3y7ddMtjm0fBSEehxZmKSfJGjR68H6NG9Yr9s3j4CtrbxCdf7I8 Clp3nJUu+ltEdjVepz/s/vUb1lQ== X-Received: by 2002:adf:e84f:: with SMTP id d15mr3032033wrn.296.1588672758917; Tue, 05 May 2020 02:59:18 -0700 (PDT) X-Google-Smtp-Source: APiQypJShUnYILHJ8U5brRMrIssUCnaErztaa25cV9VvPFQqdJVpx0Vrslt1Z2BIuQkZt6KNTl+ItA== X-Received: by 2002:adf:e84f:: with SMTP id d15mr3032013wrn.296.1588672758743; Tue, 05 May 2020 02:59:18 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:18 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 01/12] vfs: allow unprivileged whiteout creation Date: Tue, 5 May 2020 11:59:04 +0200 Message-Id: <20200505095915.11275-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Whiteouts, unlike real device node should not require privileges to create. The general concern with device nodes is that opening them can have side effects. The kernel already avoids zero major (see Documentation/admin-guide/devices.txt). To be on the safe side the patch explicitly forbids registering a char device with 0/0 number (see cdev_add()). This guarantees that a non-O_PATH open on a whiteout will fail with ENODEV; i.e. it won't have any side effect. Signed-off-by: Miklos Szeredi --- fs/char_dev.c | 3 +++ fs/namei.c | 17 ++++------------- include/linux/device_cgroup.h | 3 +++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/char_dev.c b/fs/char_dev.c index c5e6eff5a381..ba0ded7842a7 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -483,6 +483,9 @@ int cdev_add(struct cdev *p, dev_t dev, unsigned count) p->dev = dev; p->count = count; + if (WARN_ON(dev == WHITEOUT_DEV)) + return -EBUSY; + error = kobj_map(cdev_map, dev, count, NULL, exact_match, exact_lock, p); if (error) diff --git a/fs/namei.c b/fs/namei.c index a320371899cf..b48dc2e03888 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3505,12 +3505,14 @@ EXPORT_SYMBOL(user_path_create); int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { + bool is_whiteout = S_ISCHR(mode) && dev == WHITEOUT_DEV; int error = may_create(dir, dentry); if (error) return error; - if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD)) + if ((S_ISCHR(mode) || S_ISBLK(mode)) && !is_whiteout && + !capable(CAP_MKNOD)) return -EPERM; if (!dir->i_op->mknod) @@ -4345,9 +4347,6 @@ static int do_renameat2(int olddfd, const char __user *oldname, int newdfd, (flags & RENAME_EXCHANGE)) return -EINVAL; - if ((flags & RENAME_WHITEOUT) && !capable(CAP_MKNOD)) - return -EPERM; - if (flags & RENAME_EXCHANGE) target_flags = 0; @@ -4485,15 +4484,7 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna int vfs_whiteout(struct inode *dir, struct dentry *dentry) { - int error = may_create(dir, dentry); - if (error) - return error; - - if (!dir->i_op->mknod) - return -EPERM; - - return dir->i_op->mknod(dir, dentry, - S_IFCHR | WHITEOUT_MODE, WHITEOUT_DEV); + return vfs_mknod(dir, dentry, S_IFCHR | WHITEOUT_MODE, WHITEOUT_DEV); } EXPORT_SYMBOL(vfs_whiteout); diff --git a/include/linux/device_cgroup.h b/include/linux/device_cgroup.h index fa35b52e0002..57e63bd63370 100644 --- a/include/linux/device_cgroup.h +++ b/include/linux/device_cgroup.h @@ -51,6 +51,9 @@ static inline int devcgroup_inode_mknod(int mode, dev_t dev) if (!S_ISBLK(mode) && !S_ISCHR(mode)) return 0; + if (S_ISCHR(mode) && dev == WHITEOUT_DEV) + return 0; + if (S_ISBLK(mode)) type = DEVCG_DEV_BLOCK; else From patchwork Tue May 5 09:59:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528605 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA8FC1668 for ; Tue, 5 May 2020 09:59:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B474F206B9 for ; Tue, 5 May 2020 09:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RqPRL6RM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728706AbgEEJ7a (ORCPT ); Tue, 5 May 2020 05:59:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:39184 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728268AbgEEJ7Z (ORCPT ); Tue, 5 May 2020 05:59:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OyszvEdfhOqvydMHG0rBHFkiY38nX4lEEIw22aCBSnI=; b=RqPRL6RMw6SXPnNnvAJFbQ3DZfFAHh46tgV8pf3gdOHamDBp4x4d7pZpVQgO1fv2/5PQE8 Km2uNdKYJJHv4xEShejk7hyR3e4ZaiAcqH8z5MZCQ68ifl86GPwfH6LFFNecIs0/F51lKy 5AiJIbJPXan0wJxudUDhiuNt2VIezK8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-379-57jQg6vDO6muvhGUcfDxlg-1; Tue, 05 May 2020 05:59:21 -0400 X-MC-Unique: 57jQg6vDO6muvhGUcfDxlg-1 Received: by mail-wr1-f71.google.com with SMTP id f2so967771wrm.9 for ; Tue, 05 May 2020 02:59:21 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OyszvEdfhOqvydMHG0rBHFkiY38nX4lEEIw22aCBSnI=; b=cy8Lx1Yp6MEU+/qzzlQ8cU+0VDp4IWNOqsSLBTLBx3Sg+6PP3di0v99ZjnXMQgUM++ i30o67T2uX9uTTq6xkY8Z8ha/kkUclZDjewZrqPm7S9hGXvchNI+ZxBxLRsMctJ6H5fq QAGbH4eJ7x+lEqwfYvXVekZ47MLKIG0CG7FpH7nEHDUlz9tD8V58gUe6YIyBK6WTNdCP W7POD7Hg/6+H6qEPP0PtC5xAas4pjKirenMN2Z2bc6qurdeN7fhKaMek0e4bEVQVgxAW xLkhAsT90evAkS10lqC5EoziD5y+FnmmGefCO68NWJrt8yQrzIQayD5Xb9uQw9EKen8M ORuw== X-Gm-Message-State: AGi0PubEfPwybKyowXblEsSUWqlD1ve66ZohUViIViDm4DJvYeyXqYJ0 2ig14W/p3t2L/3IN9xNbkr/8VBKZZLaZosMaCfOAasTbXdYp0lfcw2Y1wmJGUxU4GI5fIX4w/Sw 3AacJqfJ5lpqu83kkJhR6Sz0ZAA== X-Received: by 2002:a5d:65ce:: with SMTP id e14mr2760084wrw.314.1588672760178; Tue, 05 May 2020 02:59:20 -0700 (PDT) X-Google-Smtp-Source: APiQypJvCZOQu0cs8h545uYlQatVCv4VfNKe6VY53mr88ncSgs6P0niA5ZZfVwJnwn/2Trdin8ScfQ== X-Received: by 2002:a5d:65ce:: with SMTP id e14mr2760067wrw.314.1588672760001; Tue, 05 May 2020 02:59:20 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:19 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Avi Kivity , Giuseppe Scrivano , stable@vger.kernel.org Subject: [PATCH 02/12] aio: fix async fsync creds Date: Tue, 5 May 2020 11:59:05 +0200 Message-Id: <20200505095915.11275-3-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Avi Kivity reports that on fuse filesystems running in a user namespace asyncronous fsync fails with EOVERFLOW. The reason is that f_ops->fsync() is called with the creds of the kthread performing aio work instead of the creds of the process originally submitting IOCB_CMD_FSYNC. Fuse sends the creds of the caller in the request header and it needs to translate the uid and gid into the server's user namespace. Since the kthread is running in init_user_ns, the translation will fail and the operation returns an error. It can be argued that fsync doesn't actually need any creds, but just zeroing out those fields in the header (as with requests that currently don't take creds) is a backward compatibility risk. Instead of working around this issue in fuse, solve the core of the problem by calling the filesystem with the proper creds. Reported-by: Avi Kivity Tested-by: Giuseppe Scrivano Fixes: c9582eb0ff7d ("fuse: Fail all requests with invalid uids or gids") Cc: stable@vger.kernel.org # 4.18+ Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/aio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/aio.c b/fs/aio.c index 5f3d3d814928..6483f9274d5e 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -176,6 +176,7 @@ struct fsync_iocb { struct file *file; struct work_struct work; bool datasync; + struct cred *creds; }; struct poll_iocb { @@ -1589,8 +1590,11 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, static void aio_fsync_work(struct work_struct *work) { struct aio_kiocb *iocb = container_of(work, struct aio_kiocb, fsync.work); + const struct cred *old_cred = override_creds(iocb->fsync.creds); iocb->ki_res.res = vfs_fsync(iocb->fsync.file, iocb->fsync.datasync); + revert_creds(old_cred); + put_cred(iocb->fsync.creds); iocb_put(iocb); } @@ -1604,6 +1608,10 @@ static int aio_fsync(struct fsync_iocb *req, const struct iocb *iocb, if (unlikely(!req->file->f_op->fsync)) return -EINVAL; + req->creds = prepare_creds(); + if (!req->creds) + return -ENOMEM; + req->datasync = datasync; INIT_WORK(&req->work, aio_fsync_work); schedule_work(&req->work); From patchwork Tue May 5 09:59:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4AA21668 for ; Tue, 5 May 2020 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6EF7206E6 for ; Tue, 5 May 2020 09:59:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HkKRhpID" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728709AbgEEJ7b (ORCPT ); Tue, 5 May 2020 05:59:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:27119 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728697AbgEEJ71 (ORCPT ); Tue, 5 May 2020 05:59:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5RqCFyq/fXvFwN1UMB3LjzTaQRZFXgAWBLj/FQyRgmQ=; b=HkKRhpID5IMWnnjuqSwaK9fTGnP81kuBKsnP1hwd5kfjsLiF/0WnUCBOtragjpF8DDRkZC fkd5UFzBhEcviD9fLe4G9RxQHSDWiQ38dNhM554sqHWKHWa1pIj+Papc10QKMRZJNFJcLw t72lXyPXVsYma/yW0ByaNkkmb8LYwxI= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-NWnD8ddpPTyyb3-6BexH3g-1; Tue, 05 May 2020 05:59:23 -0400 X-MC-Unique: NWnD8ddpPTyyb3-6BexH3g-1 Received: by mail-wm1-f71.google.com with SMTP id f128so803618wmf.8 for ; Tue, 05 May 2020 02:59:23 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=5RqCFyq/fXvFwN1UMB3LjzTaQRZFXgAWBLj/FQyRgmQ=; b=RTA3WatTXr7TAbiQtjHtbvUSQQpdu5Y2tKfTJCoTwOMC7MZAkMRSHD8BUpQqmsDA8A aTykZk9XvK1ymKh0ZxdqufCM5tn9vWhUI9LAunZLyJd81fKfzhOEAkZMN6eEUKgqyVG/ QHh7Ux1RTM3TCSAWpRt/1hm9M7jJDirWsGia/BXKW+gRr6L/r0++Zfo+HFG2YtPFZHGx cFYMfn9DiF7/RpeovCGmRzDVr4PnzDcZziwMa9V6kD0GqpXsj6gNNFT2EQbfq1qfXyNV wA4upsTkDeuF5ncUf04VdNCIa+dbHU3Vzk/9wN8aP2BzvMjJx1RcNFC7CdaAZKb37yUN Mq/A== X-Gm-Message-State: AGi0PubCexnAvfCGGZ4PLx4Yn3IxEKBHGpq3PV7SAbA6BxsfTiENUrwI OFnk/3sNqd8JV7nuu2B3yCJ5DxrC9p61Y9aoG6RUFgFOf9C+B1l/q4OSNdTgq31IzgT7YaMjH7u WsnlcobhCQeVAmeo7pr8t5xjNlg== X-Received: by 2002:a1c:5f56:: with SMTP id t83mr2432535wmb.61.1588672761484; Tue, 05 May 2020 02:59:21 -0700 (PDT) X-Google-Smtp-Source: APiQypIqfKdg8/E8gDuoSgLiqGy1Nspa1i1D3kvm29Fyrghvc6vvFSihgDimsNF46fPMZzhGipLHvw== X-Received: by 2002:a1c:5f56:: with SMTP id t83mr2432500wmb.61.1588672761063; Tue, 05 May 2020 02:59:21 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:20 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Karel Zak Subject: [PATCH 03/12] proc/mounts: add cursor Date: Tue, 5 May 2020 11:59:06 +0200 Message-Id: <20200505095915.11275-4-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If mounts are deleted after a read(2) call on /proc/self/mounts (or its kin), the subsequent read(2) could miss a mount that comes after the deleted one in the list. This is because the file position is interpreted as the number mount entries from the start of the list. E.g. first read gets entries #0 to #9; the seq file index will be 10. Then entry #5 is deleted, resulting in #10 becoming #9 and #11 becoming #10, etc... The next read will continue from entry #10, and #9 is missed. Solve this by adding a cursor entry for each open instance. Taking the global namespace_sem for write seems excessive, since we are only dealing with a per-namespace list. Instead add a per-namespace spinlock and use that together with namespace_sem taken for read to protect against concurrent modification of the mount list. This may reduce parallelism of is_local_mountpoint(), but it's hardly a big contention point. We could also use RCU freeing of cursors to make traversal not need additional locks, if that turns out to be neceesary. Only move the cursor once for each read (cursor is not added on open) to minimize cacheline invalidation. When EOF is reached, the cursor is taken off the list, in order to prevent an excessive number of cursors due to inactive open file descriptors. Reported-by: Karel Zak Signed-off-by: Miklos Szeredi --- fs/mount.h | 12 ++++-- fs/namespace.c | 91 +++++++++++++++++++++++++++++++++++-------- fs/proc_namespace.c | 4 +- include/linux/mount.h | 4 +- 4 files changed, 90 insertions(+), 21 deletions(-) diff --git a/fs/mount.h b/fs/mount.h index 711a4093e475..c7abb7b394d8 100644 --- a/fs/mount.h +++ b/fs/mount.h @@ -9,7 +9,13 @@ struct mnt_namespace { atomic_t count; struct ns_common ns; struct mount * root; + /* + * Traversal and modification of .list is protected by either + * - taking namespace_sem for write, OR + * - taking namespace_sem for read AND taking .ns_lock. + */ struct list_head list; + spinlock_t ns_lock; struct user_namespace *user_ns; struct ucounts *ucounts; u64 seq; /* Sequence number to prevent loops */ @@ -133,9 +139,7 @@ struct proc_mounts { struct mnt_namespace *ns; struct path root; int (*show)(struct seq_file *, struct vfsmount *); - void *cached_mount; - u64 cached_event; - loff_t cached_index; + struct mount cursor; }; extern const struct seq_operations mounts_op; @@ -153,3 +157,5 @@ static inline bool is_anon_ns(struct mnt_namespace *ns) { return ns->seq == 0; } + +extern void mnt_cursor_del(struct mnt_namespace *ns, struct mount *cursor); diff --git a/fs/namespace.c b/fs/namespace.c index a28e4db075ed..b59b4e4e9a8a 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -648,6 +648,21 @@ struct vfsmount *lookup_mnt(const struct path *path) return m; } +static inline void lock_ns_list(struct mnt_namespace *ns) +{ + spin_lock(&ns->ns_lock); +} + +static inline void unlock_ns_list(struct mnt_namespace *ns) +{ + spin_unlock(&ns->ns_lock); +} + +static inline bool mnt_is_cursor(struct mount *mnt) +{ + return mnt->mnt.mnt_flags & MNT_CURSOR; +} + /* * __is_local_mountpoint - Test to see if dentry is a mountpoint in the * current mount namespace. @@ -673,11 +688,15 @@ bool __is_local_mountpoint(struct dentry *dentry) goto out; down_read(&namespace_sem); + lock_ns_list(ns); list_for_each_entry(mnt, &ns->list, mnt_list) { + if (mnt_is_cursor(mnt)) + continue; is_covered = (mnt->mnt_mountpoint == dentry); if (is_covered) break; } + unlock_ns_list(ns); up_read(&namespace_sem); out: return is_covered; @@ -1245,46 +1264,71 @@ struct vfsmount *mnt_clone_internal(const struct path *path) } #ifdef CONFIG_PROC_FS +static struct mount *mnt_list_next(struct mnt_namespace *ns, + struct list_head *p) +{ + struct mount *mnt, *ret = NULL; + + lock_ns_list(ns); + for (p = p->next; p != &ns->list; p = p->next) { + mnt = list_entry(p, typeof(*mnt), mnt_list); + if (!mnt_is_cursor(mnt)) { + ret = mnt; + break; + } + } + unlock_ns_list(ns); + + return ret; +} + /* iterator; we want it to have access to namespace_sem, thus here... */ static void *m_start(struct seq_file *m, loff_t *pos) { struct proc_mounts *p = m->private; + struct list_head *prev; down_read(&namespace_sem); - if (p->cached_event == p->ns->event) { - void *v = p->cached_mount; - if (*pos == p->cached_index) - return v; - if (*pos == p->cached_index + 1) { - v = seq_list_next(v, &p->ns->list, &p->cached_index); - return p->cached_mount = v; - } + if (!*pos) { + prev = &p->ns->list; + } else { + prev = &p->cursor.mnt_list; + + /* Read after we'd reached the end? */ + if (list_empty(prev)) + return NULL; } - p->cached_event = p->ns->event; - p->cached_mount = seq_list_start(&p->ns->list, *pos); - p->cached_index = *pos; - return p->cached_mount; + return mnt_list_next(p->ns, prev); } static void *m_next(struct seq_file *m, void *v, loff_t *pos) { struct proc_mounts *p = m->private; + struct mount *mnt = v; - p->cached_mount = seq_list_next(v, &p->ns->list, pos); - p->cached_index = *pos; - return p->cached_mount; + ++*pos; + return mnt_list_next(p->ns, &mnt->mnt_list); } static void m_stop(struct seq_file *m, void *v) { + struct proc_mounts *p = m->private; + struct mount *mnt = v; + + lock_ns_list(p->ns); + if (mnt) + list_move_tail(&p->cursor.mnt_list, &mnt->mnt_list); + else + list_del_init(&p->cursor.mnt_list); + unlock_ns_list(p->ns); up_read(&namespace_sem); } static int m_show(struct seq_file *m, void *v) { struct proc_mounts *p = m->private; - struct mount *r = list_entry(v, struct mount, mnt_list); + struct mount *r = v; return p->show(m, &r->mnt); } @@ -1294,6 +1338,15 @@ const struct seq_operations mounts_op = { .stop = m_stop, .show = m_show, }; + +void mnt_cursor_del(struct mnt_namespace *ns, struct mount *cursor) +{ + down_read(&namespace_sem); + lock_ns_list(ns); + list_del(&cursor->mnt_list); + unlock_ns_list(ns); + up_read(&namespace_sem); +} #endif /* CONFIG_PROC_FS */ /** @@ -3202,6 +3255,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a atomic_set(&new_ns->count, 1); INIT_LIST_HEAD(&new_ns->list); init_waitqueue_head(&new_ns->poll); + spin_lock_init(&new_ns->ns_lock); new_ns->user_ns = get_user_ns(user_ns); new_ns->ucounts = ucounts; return new_ns; @@ -3842,10 +3896,14 @@ static bool mnt_already_visible(struct mnt_namespace *ns, bool visible = false; down_read(&namespace_sem); + lock_ns_list(ns); list_for_each_entry(mnt, &ns->list, mnt_list) { struct mount *child; int mnt_flags; + if (mnt_is_cursor(mnt)) + continue; + if (mnt->mnt.mnt_sb->s_type != sb->s_type) continue; @@ -3893,6 +3951,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns, next: ; } found: + unlock_ns_list(ns); up_read(&namespace_sem); return visible; } diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c index 273ee82d8aa9..e4d70c0dffe9 100644 --- a/fs/proc_namespace.c +++ b/fs/proc_namespace.c @@ -279,7 +279,8 @@ static int mounts_open_common(struct inode *inode, struct file *file, p->ns = ns; p->root = root; p->show = show; - p->cached_event = ~0ULL; + INIT_LIST_HEAD(&p->cursor.mnt_list); + p->cursor.mnt.mnt_flags = MNT_CURSOR; return 0; @@ -296,6 +297,7 @@ static int mounts_release(struct inode *inode, struct file *file) struct seq_file *m = file->private_data; struct proc_mounts *p = m->private; path_put(&p->root); + mnt_cursor_del(p->ns, &p->cursor); put_mnt_ns(p->ns); return seq_release_private(inode, file); } diff --git a/include/linux/mount.h b/include/linux/mount.h index bf8cc4108b8f..7edac8c7a9c1 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -50,7 +50,8 @@ struct fs_context; #define MNT_ATIME_MASK (MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME ) #define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \ - MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED) + MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED | \ + MNT_CURSOR) #define MNT_INTERNAL 0x4000 @@ -64,6 +65,7 @@ struct fs_context; #define MNT_SYNC_UMOUNT 0x2000000 #define MNT_MARKED 0x4000000 #define MNT_UMOUNT 0x8000000 +#define MNT_CURSOR 0x10000000 struct vfsmount { struct dentry *mnt_root; /* root of the mounted tree */ From patchwork Tue May 5 09:59:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528603 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 403A01862 for ; Tue, 5 May 2020 09:59:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2790720721 for ; Tue, 5 May 2020 09:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FW5zZQlR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728705AbgEEJ7a (ORCPT ); Tue, 5 May 2020 05:59:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56849 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728695AbgEEJ70 (ORCPT ); Tue, 5 May 2020 05:59:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vc/4f/MdW3BVxDRO0Zg9qb0kjvZ8rZJADpJurBxPrbA=; b=FW5zZQlRdzm4fLn8qvhVX7maKsVB5Q/nIgISDElokCO374QQr+iWXMfzRhvTKWjlCfj5Rf qI6TZcj9osTMkmy070cg+DoBSGWiZsRwG87zSVVvW9PvrfNdc+29KHagpBJ70ed7yA3zpJ zB0+WhGRJtqzWtx1osrQUxnyRDXM2zQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-DpPSvXxYN124lHAOOaSc3w-1; Tue, 05 May 2020 05:59:23 -0400 X-MC-Unique: DpPSvXxYN124lHAOOaSc3w-1 Received: by mail-wm1-f72.google.com with SMTP id h184so809489wmf.5 for ; Tue, 05 May 2020 02:59:23 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vc/4f/MdW3BVxDRO0Zg9qb0kjvZ8rZJADpJurBxPrbA=; b=bEeRpJemrlGfaN2Id/vkXX4HsyZN993ns9KooxOs3JjuKTUcKQ9fZP51v6K9jvLdbJ iQ08Kdm5yDci0TVq78BuupdWOYp2i5gnKP9HwJ+42YlTN9sRupLHptgkTbuOv8os+oAU 43pdh+cpNR+F+R+3KshaZNx0pi1RgvgyAtpbEIR9173C77s0WwYDVpVVsF77+CYqcAl7 2WF7fuEoPpqvbEibZAKcH9wmlGMMOyZtKYIvD/z9DYBi1XEfVo6uKfg5yETvooUICjwF syNJQc8YaBZtlK+Yq6yJyQukB/gtZhkaoLn/ExjCF/2gFA/JARLodFKatniXqdjwAI6L jqGw== X-Gm-Message-State: AGi0PuY3X6VOJ07o8er/VRSGDn6aObp6IZJlqdc81K1s4aaPV5bBBCQS sq72jAAQJ+A3wfW5rLOUsVPeX+EWsn7GsvEUsK2x/x0qACo5LFg2Qe2z8+QdhHzQkiuVduQpMjd SQXH9VQbsEjg8tbgxiOOK2MjCbw== X-Received: by 2002:adf:a35c:: with SMTP id d28mr2659102wrb.37.1588672762176; Tue, 05 May 2020 02:59:22 -0700 (PDT) X-Google-Smtp-Source: APiQypLmsq1mk1lZlDOqPUAUjDjMXScF3S3gI2pPbAOSnh0Yzw4qZuQmEOJmBxqDRSFZllyW+M3okw== X-Received: by 2002:adf:a35c:: with SMTP id d28mr2659089wrb.37.1588672761982; Tue, 05 May 2020 02:59:21 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:21 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 04/12] utimensat: AT_EMPTY_PATH support Date: Tue, 5 May 2020 11:59:07 +0200 Message-Id: <20200505095915.11275-5-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This makes it possible to use utimensat on an O_PATH file (including symlinks). It supersedes the nonstandard utimensat(fd, NULL, ...) form. Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/utimes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/utimes.c b/fs/utimes.c index 1d17ce98cb80..b7b927502d6e 100644 --- a/fs/utimes.c +++ b/fs/utimes.c @@ -95,13 +95,13 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, goto out; } - if (flags & ~AT_SYMLINK_NOFOLLOW) + if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) goto out; if (filename == NULL && dfd != AT_FDCWD) { struct fd f; - if (flags & AT_SYMLINK_NOFOLLOW) + if (flags) goto out; f = fdget(dfd); @@ -117,6 +117,8 @@ long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, if (!(flags & AT_SYMLINK_NOFOLLOW)) lookup_flags |= LOOKUP_FOLLOW; + if (flags & AT_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; retry: error = user_path_at(dfd, filename, lookup_flags, &path); if (error) From patchwork Tue May 5 09:59:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528607 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E5A41668 for ; Tue, 5 May 2020 09:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04FDE20721 for ; Tue, 5 May 2020 09:59:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RANGwmgP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728708AbgEEJ7b (ORCPT ); Tue, 5 May 2020 05:59:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20355 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725766AbgEEJ71 (ORCPT ); Tue, 5 May 2020 05:59:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uXPdPpU//6NLTX0yp76oURrl678mDyxymrzUtOnXBDU=; b=RANGwmgPMAJmIgf9ksc/LQwPiDDnALD4DC+JW2okD+e+cYig1Cij8SzkOE8QX+qUJPqIT2 A9RfLvKOZZSgQL/Q8vI65ZzcOtp8aMkOJ00DY9UbZdJ8zOPnCD/37c4TRRCpo9x6mHJI7y +BG3vpXwKdIS2AHiiZaN/ip2AT5vOSc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-YxmsA8lpNVKpRdBwTr9_-A-1; Tue, 05 May 2020 05:59:24 -0400 X-MC-Unique: YxmsA8lpNVKpRdBwTr9_-A-1 Received: by mail-wm1-f70.google.com with SMTP id b203so615350wmd.6 for ; Tue, 05 May 2020 02:59:24 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=uXPdPpU//6NLTX0yp76oURrl678mDyxymrzUtOnXBDU=; b=qn0Ja+ZRzZQJj6c0LOCP6VM+LwE43BHtzd6dyynHfjq5xtMYZuX6/WJC0kcdmfpBXs XnwiZeDRvMdlZjSNLglvKCXuEAx9d5WO3VCCwVAFWJ3E3m75WrXFevSz3B5vFwAD5Ju/ y+Jpi3ExNZnHa97vtmhs5qJHL2W9SpVRuBj6Ivtp8K4KEOJz3vNXbiDvEV26liPf/2mK u31nTEBsctpxc24iasMSjPez4mQWWMwnHUwoEx9uIbBH4Yd/FB0VxQiJKkiWr1Xo+xZb 07SAkhEt4iicCp1cRgzE7UEpaJ1+radS3aew1WVgLd7vOtg4kab6zoVQaA27buZbKSxr 1T3g== X-Gm-Message-State: AGi0PuYTwWCbJoeDe6CehMNWDP5XZHdSDdUneCASC8HPhjvOKRUjPjF/ 3jXCghKyaaSww0luSb3xL4+pl2X3fxHQWD2dwq5C2xQYnCcZ6YeSjRWI1aTSm405J3qqri5xtdR XlSbGbodntBgjnZSA3wDjkWapkA== X-Received: by 2002:adf:e4cf:: with SMTP id v15mr2702548wrm.43.1588672763346; Tue, 05 May 2020 02:59:23 -0700 (PDT) X-Google-Smtp-Source: APiQypJqRK1MS4jlWY5wrRzSEFNVi6UndErraZRRBZ6ElvdVgw78BsljCVXnnHyVBCvoB0wglhUmNQ== X-Received: by 2002:adf:e4cf:: with SMTP id v15mr2702532wrm.43.1588672763129; Tue, 05 May 2020 02:59:23 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:22 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 05/12] f*xattr: allow O_PATH descriptors Date: Tue, 5 May 2020 11:59:08 +0200 Message-Id: <20200505095915.11275-6-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This allows xattr ops on symlink/special files referenced by an O_PATH descriptor without having to play games with /proc/self/fd/NN (which doesn't work for symlinks anyway). This capability is the same as would be given by introducing ...at() variants with an AT_EMPTY_PATH argument. Looking at getattr/setattr type syscalls, this is allowed for fstatat() and fchownat(), but not for fchmodat() and utimensat(). What's the logic? While this carries a minute risk of someone relying on the property of xattr syscalls rejecting O_PATH descriptors, it saves the trouble of introducing another set of syscalls. Only file->f_path and file->f_inode are accessed in these functions. Current versions return EBADF, hence easy to detect the presense of this feature and fall back in case it's missing. Signed-off-by: Miklos Szeredi --- fs/xattr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/xattr.c b/fs/xattr.c index e13265e65871..7080bb4f3f14 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -495,7 +495,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname, SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, const void __user *,value, size_t, size, int, flags) { - struct fd f = fdget(fd); + struct fd f = fdget_raw(fd); int error = -EBADF; if (!f.file) @@ -587,7 +587,7 @@ SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname, SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, void __user *, value, size_t, size) { - struct fd f = fdget(fd); + struct fd f = fdget_raw(fd); ssize_t error = -EBADF; if (!f.file) @@ -662,7 +662,7 @@ SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list, SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) { - struct fd f = fdget(fd); + struct fd f = fdget_raw(fd); ssize_t error = -EBADF; if (!f.file) @@ -727,7 +727,7 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname, SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) { - struct fd f = fdget(fd); + struct fd f = fdget_raw(fd); int error = -EBADF; if (!f.file) From patchwork Tue May 5 09:59:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABC1D1668 for ; Tue, 5 May 2020 09:59:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9318D20721 for ; Tue, 5 May 2020 09:59:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cUIGKLVS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728713AbgEEJ7d (ORCPT ); Tue, 5 May 2020 05:59:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:52577 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728700AbgEEJ73 (ORCPT ); Tue, 5 May 2020 05:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rEQgq0n2zQNPcIwMRs6h5ARye1Rkk4BmUOM1dwLbDA=; b=cUIGKLVShKMg8eDE1wisxDY2aMbM1Beg4NDXtTHiyrZvfseIMEsV/h+5ZtdnTCi6M5eP6g BIVBZ8FcvzuvarSzCCN6yGjj5+B3WJudeiRyRydnBvjHjp1LaUWgq3tZEa/BL7FxP/jKI1 s6CrFHbRduRFtXDHZKf2jq8+cmiR39I= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-YXYwpnjSPn-9ZMMJp-qHhw-1; Tue, 05 May 2020 05:59:26 -0400 X-MC-Unique: YXYwpnjSPn-9ZMMJp-qHhw-1 Received: by mail-wr1-f71.google.com with SMTP id q13so964642wrn.14 for ; Tue, 05 May 2020 02:59:26 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9rEQgq0n2zQNPcIwMRs6h5ARye1Rkk4BmUOM1dwLbDA=; b=BQPY35RxSKUu1uquNqfoR7QA5XhWZE8ztMlYpOPY3t4ptfmsaw9sugVmSHq/BUYc0V aRls2hUv15DvJAVmnbaOQaEQ1qMmpWifzOXzWgnr3Lr5fYT24uNOlFo+UGbmOuGhIooc 6/Fqs693l2+rdT+lKd2a5xl5yGV9i6gHU17QNxlp1Zogw8oP/qw5IkJZ0qnsKWL53nRv zpPvgRV6ecfDW34WlLfcSDWk8OfpPtsc2S99EIxpsrIwRhbXn9H6JO3le6chp5VVAyJ/ /zvEnAE0Uik4w2cHOcY5kIkdPrna0XKyE4ZYwhuqJAr7R2S+X9xVEK7CuHKofZjL6UxC s4Gg== X-Gm-Message-State: AGi0Pua2W99lAn0QyV35ihlxiOGDc11cJqLQnWFCOJFQBMTJT/456KAA 7iE/Rm2OHcCc26zWZSVA4icr83YrzQEuTekhbNnPwngcgfiRpJHAh9qZ20FrC5Og30DRzQFJCI/ yU6+SbaOXAdV9ZINEAAKrhjnPmw== X-Received: by 2002:a1c:6405:: with SMTP id y5mr2400168wmb.63.1588672764605; Tue, 05 May 2020 02:59:24 -0700 (PDT) X-Google-Smtp-Source: APiQypIhMi3j2nqO2MWoy8CJJ/UAxBVFaxgdYOm9aJaKfjOxrKh9K6Ko84tRV230umXoxFOuIT8unA== X-Received: by 2002:a1c:6405:: with SMTP id y5mr2400148wmb.63.1588672764365; Tue, 05 May 2020 02:59:24 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:23 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, David Howells , Michael Kerrisk Subject: [PATCH 06/12] uapi: deprecate STATX_ALL Date: Tue, 5 May 2020 11:59:09 +0200 Message-Id: <20200505095915.11275-7-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Constants of the *_ALL type can be actively harmful due to the fact that developers will usually fail to consider the possible effects of future changes to the definition. Deprecate STATX_ALL in the uapi, while no damage has been done yet. We could keep something like this around in the kernel, but there's actually no point, since all filesystems should be explicitly checking flags that they support and not rely on the VFS masking unknown ones out: a flag could be known to the VFS, yet not known to the filesystem. Signed-off-by: Miklos Szeredi Cc: David Howells Cc: Michael Kerrisk Reviewed-by: Christoph Hellwig --- fs/stat.c | 1 - include/uapi/linux/stat.h | 11 ++++++++++- samples/vfs/test-statx.c | 2 +- tools/include/uapi/linux/stat.h | 11 ++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 030008796479..a6709e7ba71d 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -70,7 +70,6 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat, memset(stat, 0, sizeof(*stat)); stat->result_mask |= STATX_BASIC_STATS; - request_mask &= STATX_ALL; query_flags &= KSTAT_QUERY_FLAGS; /* allow the fs to override these if it really wants to */ diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index ad80a5c885d5..d1192783139a 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -148,9 +148,18 @@ struct statx { #define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */ #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ -#define STATX_ALL 0x00000fffU /* All currently supported flags */ + #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ +#ifndef __KERNEL__ +/* + * This is deprecated, and shall remain the same value in the future. To avoid + * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME) + * instead. + */ +#define STATX_ALL 0x00000fffU +#endif + /* * Attributes to be found in stx_attributes and masked in stx_attributes_mask. * diff --git a/samples/vfs/test-statx.c b/samples/vfs/test-statx.c index a3d68159fb51..76c577ea4fd8 100644 --- a/samples/vfs/test-statx.c +++ b/samples/vfs/test-statx.c @@ -216,7 +216,7 @@ int main(int argc, char **argv) struct statx stx; int ret, raw = 0, atflag = AT_SYMLINK_NOFOLLOW; - unsigned int mask = STATX_ALL; + unsigned int mask = STATX_BASIC_STATS | STATX_BTIME; for (argv++; *argv; argv++) { if (strcmp(*argv, "-F") == 0) { diff --git a/tools/include/uapi/linux/stat.h b/tools/include/uapi/linux/stat.h index ad80a5c885d5..d1192783139a 100644 --- a/tools/include/uapi/linux/stat.h +++ b/tools/include/uapi/linux/stat.h @@ -148,9 +148,18 @@ struct statx { #define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */ #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ -#define STATX_ALL 0x00000fffU /* All currently supported flags */ + #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ +#ifndef __KERNEL__ +/* + * This is deprecated, and shall remain the same value in the future. To avoid + * confusion please use the equivalent (STATX_BASIC_STATS | STATX_BTIME) + * instead. + */ +#define STATX_ALL 0x00000fffU +#endif + /* * Attributes to be found in stx_attributes and masked in stx_attributes_mask. * From patchwork Tue May 5 09:59:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C0131668 for ; Tue, 5 May 2020 09:59:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84A5120721 for ; Tue, 5 May 2020 09:59:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="O3p7RfBX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728714AbgEEJ7d (ORCPT ); Tue, 5 May 2020 05:59:33 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:48343 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728701AbgEEJ73 (ORCPT ); Tue, 5 May 2020 05:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4J/LkBdEboueddkWDbGtL76FcH5ycOdWjbYh+JqdAEM=; b=O3p7RfBX67osbbrnDBnYrR/QEbI1oPvmJNshzZPAb+4T/yfUhtYg/q5HJKhUQ43QUs22fL UgcVEBh7tPHZHf3K//PED/HojjlMysxULjl2xmbhQ0Wop3gH1fs+mHsjeFxILC6rEtbNxG 1CuH6cmcS0xnRmoKOIB1G8FWpZPzohA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-mhHYd9bYPYCUp-Kr2-KFAg-1; Tue, 05 May 2020 05:59:27 -0400 X-MC-Unique: mhHYd9bYPYCUp-Kr2-KFAg-1 Received: by mail-wr1-f71.google.com with SMTP id p8so971435wrj.5 for ; Tue, 05 May 2020 02:59:26 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4J/LkBdEboueddkWDbGtL76FcH5ycOdWjbYh+JqdAEM=; b=FX9iHU1MSRy6biQxVftd0qUCcwccOGHEREUWNxPwaYOVyMFHdagILwxHspRZytUceW NgczlgCEd0FV+e9+0XNJPUuOQQaStlxqAcOhmitRCFG/558s3gr4xhHNiheXYguAG+Kz WZq0EWI30nyL6fnWQ7FXuQ479b4uUUNsn8ShuLMIYdp14tPzYx3nGX2uO5pQK4hgF8ZE R90ICx4N/J4V5IGdbTUhpx7mL7W1Nz3EDaD9gXhp2WvFLHKuEsIGFuUEiZoJCtbtsJJd eQcDNBsK0c62kqNeubhPIixHPS0QJkb2YnV7RzuxqJ33qdJyJ1sZn0yzvcKqwBlI1TGO fNQA== X-Gm-Message-State: AGi0PuYwTIim1G8xTINXbCozPagqNQEFNPmFiaRQVU5hS+B+oNznjFrB 9FyQmEdgBZKFqFB+RJH4h9Xx34et9y3Nf6pMsNQugqEI1u6KX0+MLsXIiRymdnSLfTlbeE5uLMw xDNKMfxiFMWif0rbMS/wJD3CTbg== X-Received: by 2002:a1c:bc09:: with SMTP id m9mr2446448wmf.145.1588672765868; Tue, 05 May 2020 02:59:25 -0700 (PDT) X-Google-Smtp-Source: APiQypK28sptWzG05TBfnidx/q2aKF56XjU0DY89EO48ZN2COM1CLb9sQWcKg09AMb/ywFhqkXje2w== X-Received: by 2002:a1c:bc09:: with SMTP id m9mr2446431wmf.145.1588672765716; Tue, 05 May 2020 02:59:25 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:24 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, David Howells Subject: [PATCH 07/12] statx: don't clear STATX_ATIME on SB_RDONLY Date: Tue, 5 May 2020 11:59:10 +0200 Message-Id: <20200505095915.11275-8-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org IS_NOATIME(inode) is defined as __IS_FLG(inode, SB_RDONLY|SB_NOATIME), so generic_fillattr() will clear STATX_ATIME from the result_mask if the super block is marked read only. This was probably not the intention, so fix to only clear STATX_ATIME if the fs doesn't support atime at all. Signed-off-by: Miklos Szeredi Acked-by: David Howells Reviewed-by: Christoph Hellwig --- fs/stat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/stat.c b/fs/stat.c index a6709e7ba71d..f7f07d1b73cb 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -73,7 +73,8 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat, query_flags &= KSTAT_QUERY_FLAGS; /* allow the fs to override these if it really wants to */ - if (IS_NOATIME(inode)) + /* SB_NOATIME means filesystem supplies dummy atime value */ + if (inode->i_sb->s_flags & SB_NOATIME) stat->result_mask &= ~STATX_ATIME; if (IS_AUTOMOUNT(inode)) stat->attributes |= STATX_ATTR_AUTOMOUNT; From patchwork Tue May 5 09:59:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C821317E8 for ; Tue, 5 May 2020 09:59:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1BB32075A for ; Tue, 5 May 2020 09:59:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MfN088Ja" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbgEEJ7h (ORCPT ); Tue, 5 May 2020 05:59:37 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46845 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728677AbgEEJ7b (ORCPT ); Tue, 5 May 2020 05:59:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vhO62iEx0RtPui3S7bt/c3x2oJ0CRUlaneBlgdbqa+w=; b=MfN088Jas97slXBZL11DIxSR06qP1N8x/Zy4pwszXxyybqh4px0tu6222kfa2IVMLRG7zE ev7B85aFCUrw23BMmqhoZ0xmbUZNAkvXO8jk03HJ2i0rgZc51rFUO/+OFJS1ZQKFXYDmon 3YO6A9XMyWkjZSMWXA8+x0fOWBpUVi8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-5pFueuBxP8mbKAquHmPZCg-1; Tue, 05 May 2020 05:59:28 -0400 X-MC-Unique: 5pFueuBxP8mbKAquHmPZCg-1 Received: by mail-wr1-f72.google.com with SMTP id a12so974852wrv.3 for ; Tue, 05 May 2020 02:59:28 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=vhO62iEx0RtPui3S7bt/c3x2oJ0CRUlaneBlgdbqa+w=; b=nOYZakjj48/8/mLOLhL+gdRg8ScALuBDjawRjeoLeSebzJPuscsQC+TiwO9781Ubq+ qsuzhRmvtGjSBe63DvfrOYeLbjdGrZcE/2Iu80zPpnEjdiukiqggBnxpdJObL4fuNKba 35mi2WRWRZNCnKIX/3+/ZjkcCjnbsZCH+AnXcASWympLhhjUNHR5XAkltFB2Ag3f6gdx F/y6aXDb3RcJoatQN+WS6Y6R17H02kum0fbIc+pVl7uwRlZrrafLHpalSZnbrPIavp/i +rDe19AMoxOVPdlsS0pZd41Em9FUCnOgwfM5D3+brrwp0SMY1vqXBMTy5fD/fNzBjHW/ HZPw== X-Gm-Message-State: AGi0Pua7CZKKtZJq0z2iSW6YrS0v5R64I8Yvtoy9Ayi9Vr0B0rlSfdKh sHutvH+GGW4XX1nwIcoGgl8qoMZ8W0V5QPgOaJf8ZcnUxo0UEMjJpDC6xwZCnr+RZ2bDWBnLirQ Qzk3RryFAq4R5JHXykR8c5RqZFA== X-Received: by 2002:adf:e985:: with SMTP id h5mr2733968wrm.336.1588672767027; Tue, 05 May 2020 02:59:27 -0700 (PDT) X-Google-Smtp-Source: APiQypLrT7sEfnjSimPZVsnMfEeml5xIsz7yiBkGKGB/DF+v8ccxjkqwtTKT+FEh29Jau6GUwe05Wg== X-Received: by 2002:adf:e985:: with SMTP id h5mr2733954wrm.336.1588672766813; Tue, 05 May 2020 02:59:26 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:26 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 08/12] statx: add mount ID Date: Tue, 5 May 2020 11:59:11 +0200 Message-Id: <20200505095915.11275-9-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Systemd is hacking around to get it and it's trivial to add to statx, so... Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/stat.c | 4 ++++ include/linux/stat.h | 1 + include/uapi/linux/stat.h | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/stat.c b/fs/stat.c index f7f07d1b73cb..3d88c99f7743 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -22,6 +22,7 @@ #include #include "internal.h" +#include "mount.h" /** * generic_fillattr - Fill in the basic attributes from the inode struct @@ -199,6 +200,8 @@ int vfs_statx(int dfd, const char __user *filename, int flags, goto out; error = vfs_getattr(&path, stat, request_mask, flags); + stat->mnt_id = real_mount(path.mnt)->mnt_id; + stat->result_mask |= STATX_MNT_ID; path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; @@ -563,6 +566,7 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_rdev_minor = MINOR(stat->rdev); tmp.stx_dev_major = MAJOR(stat->dev); tmp.stx_dev_minor = MINOR(stat->dev); + tmp.stx_mnt_id = stat->mnt_id; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/include/linux/stat.h b/include/linux/stat.h index 528c4baad091..56614af83d4a 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -47,6 +47,7 @@ struct kstat { struct timespec64 ctime; struct timespec64 btime; /* File creation time */ u64 blocks; + u64 mnt_id; }; #endif diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index d1192783139a..d81456247f10 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -123,7 +123,10 @@ struct statx { __u32 stx_dev_major; /* ID of device containing file [uncond] */ __u32 stx_dev_minor; /* 0x90 */ - __u64 __spare2[14]; /* Spare space for future expansion */ + __u64 stx_mnt_id; + __u64 __spare2; + /* 0xa0 */ + __u64 __spare3[12]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -148,6 +151,7 @@ struct statx { #define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */ #define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */ #define STATX_BTIME 0x00000800U /* Want/got stx_btime */ +#define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ From patchwork Tue May 5 09:59:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 207C017E8 for ; Tue, 5 May 2020 09:59:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0893A20721 for ; Tue, 5 May 2020 09:59:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OQED2cmo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728717AbgEEJ7g (ORCPT ); Tue, 5 May 2020 05:59:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21275 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728711AbgEEJ7c (ORCPT ); Tue, 5 May 2020 05:59:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S8rdsU7VZlRrvrCy7TVxgch3DiKXm2iP3D5AkhKRxD0=; b=OQED2cmoNVrYcuKsZNbYtMwcYa6Alolxb37gvPMh+3DmSxnVLHVb1hspQGNm4EBW39Nb3R mx84EklOEqWRGs6ae4IhcU5X/v9esnoL5y12VuS3XnDeUOnZTL8Fv7znlvT3vDkZ+qNxV+ quJGWbszcnaelDUcOQ2VF1UxvbpSLcw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-u09qFy-VPR2MLiE96o_Rlg-1; Tue, 05 May 2020 05:59:29 -0400 X-MC-Unique: u09qFy-VPR2MLiE96o_Rlg-1 Received: by mail-wm1-f69.google.com with SMTP id d134so1061591wmd.0 for ; Tue, 05 May 2020 02:59:29 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=S8rdsU7VZlRrvrCy7TVxgch3DiKXm2iP3D5AkhKRxD0=; b=H6bh6GYROCMYDr6KQeBMxScTYCzda1AGonQCuPelthAbAWQAcdobk+P+2DotCn3BtT z0jTSBW7UlqUeXv5g16whu10MHN3dCuuTqou2ZaPSvBpxKN5TmMx8GxyRmXDHD+UsVBv D8xF0t3cS6Qm4DP67P0Hx4a5GBKNLwsY38+2omOgXIL53mkHfGGIUAC+dmiCD8P9ulAF YjHH9hqpKU9Xxzr0nfYNMul+D2hc53dy+tHKtBkS49Qf5K0yX2BNLrm7wJi7MPtOKogV IuyYNBmxKI+04+xEderS2Xc4fv1ohkdbIz/Wuk5RQtyUuihnYiAniKeWd6VD+z3Mf1zi A88A== X-Gm-Message-State: AGi0PuZdmRkAxQWG20Mrb6E8eiJSZSpQ/3CDXXgCxuao/tNAT3ci82oL dqA2iyHx3a4N5VfHHO2Oco6SbWJNefFiyg6FF/Pc0Dsxc4KJc2po3aopX7a94ae1/ebJKXlKtqW UB91cA2tCDrYhVeX5ckPzw6teqQ== X-Received: by 2002:a7b:c858:: with SMTP id c24mr2738371wml.51.1588672768134; Tue, 05 May 2020 02:59:28 -0700 (PDT) X-Google-Smtp-Source: APiQypKfyjkJgtaL4+LYdjW3wXxe6/c3F3UG4eo50ES+PNrmSRTsI9MSxsol/Rbw3fB96SggYG9J8w== X-Received: by 2002:a7b:c858:: with SMTP id c24mr2738350wml.51.1588672767972; Tue, 05 May 2020 02:59:27 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:27 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Lennart Poettering , "J . Bruce Fields" Subject: [PATCH 09/12] statx: add mount_root Date: Tue, 5 May 2020 11:59:12 +0200 Message-Id: <20200505095915.11275-10-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Determining whether a path or file descriptor refers to a mountpoint (or more precisely a mount root) is not trivial using current tools. Add a flag to statx that indicates whether the path or fd refers to the root of a mount or not. Reported-by: Lennart Poettering Reported-by: J. Bruce Fields Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/stat.c | 3 +++ include/uapi/linux/stat.h | 1 + 2 files changed, 4 insertions(+) diff --git a/fs/stat.c b/fs/stat.c index 3d88c99f7743..b9faa6cafafe 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -202,6 +202,9 @@ int vfs_statx(int dfd, const char __user *filename, int flags, error = vfs_getattr(&path, stat, request_mask, flags); stat->mnt_id = real_mount(path.mnt)->mnt_id; stat->result_mask |= STATX_MNT_ID; + if (path.mnt->mnt_root == path.dentry) + stat->attributes |= STATX_ATTR_MOUNT_ROOT; + stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT; path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL; diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index d81456247f10..6df9348bb277 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -181,6 +181,7 @@ struct statx { #define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */ #define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */ #define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */ +#define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */ #define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */ From patchwork Tue May 5 09:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69DE61862 for ; Tue, 5 May 2020 09:59:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50EC2206E6 for ; Tue, 5 May 2020 09:59:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PV4CP1Sz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbgEEJ7j (ORCPT ); Tue, 5 May 2020 05:59:39 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46772 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728716AbgEEJ7f (ORCPT ); Tue, 5 May 2020 05:59:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ZmKs7uNMAuXYKcLxlhTHc9oEghlYM1iBCHo/bbRpaA=; b=PV4CP1SzCVQI53gdA9X4roIc4LhxmmansrVc96TWqdo9cieMOOlGwHKsi1iR8mo0YIN5nk gTd0nGZysv1SqT3eqYla5ZIgX+B8mAJVXlvF2wUlFW48M6jZhXwy+tYmiA/hA14DHtLxW/ 1NxLtMQiiUp+lGgc65mcANhDrBgVVug= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-yKVnTmykN_yy5meqM7JvdQ-1; Tue, 05 May 2020 05:59:30 -0400 X-MC-Unique: yKVnTmykN_yy5meqM7JvdQ-1 Received: by mail-wm1-f70.google.com with SMTP id f81so640700wmf.2 for ; Tue, 05 May 2020 02:59:30 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=5ZmKs7uNMAuXYKcLxlhTHc9oEghlYM1iBCHo/bbRpaA=; b=dcJLqF7d+0pJ5ygvRLVffoCXNooh/ZMmJ/S7mxhqqdmx/lP+cxCw0si+01Kk5+2kyN kIT8Ns+3R1DM81G/fKIJ7lRaPabmup6sWn2jShhmr2eNUiOYb4B9wJS1CvwcDJ91jpBn YWR8RT707NPNCGgi50fL/HCOsxqBocfqU72VUAl0N0UfLp4v5nv7Fs7KoScQQfhjqT8O wrCrupJmvhNL8+BhZmOMt/kW/55yuUGllSkHss5fJwRix0YOSbe1Je8tIesvX6hmjpS5 LsMUA+dyM9tc1bLLSJjnt1eVlLb9UnrtUtxZMNEcTU/Kkz1cjVVFgNoOYvg27Nh3zGk5 tG2Q== X-Gm-Message-State: AGi0Puau2FpJsfsHFmCwKLLwouf9W7FoKXHCkpyEaohtCBEOmRdAdftB sAZ8NsYf/B9VGajr3CjGB2CTvTlOevyU8YhMd4pItkD8wMlyabVBoEtKrtEt11i31WK2XYEd2bT l6T20TftVNDUhUjGX8fP8KqeUTA== X-Received: by 2002:a5d:65ce:: with SMTP id e14mr2760797wrw.314.1588672769410; Tue, 05 May 2020 02:59:29 -0700 (PDT) X-Google-Smtp-Source: APiQypLPVZHNp9aWFnY2Sb5U8Q+FRbNPRZLMtPwftyVFubSyDhJrN7rZP0+gFK+QpsdvdVG4Y7nCmg== X-Received: by 2002:a5d:65ce:: with SMTP id e14mr2760784wrw.314.1588672769276; Tue, 05 May 2020 02:59:29 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:28 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 10/12] vfs: don't parse forbidden flags Date: Tue, 5 May 2020 11:59:13 +0200 Message-Id: <20200505095915.11275-11-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Makes little sense to keep this blacklist synced with what mount(8) parses and what it doesn't. E.g. it has various forms of "*atime" options, but not "atime"... Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/fs_context.c | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/fs/fs_context.c b/fs/fs_context.c index fc9f6ef93b55..07e09bcf256c 100644 --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -57,40 +57,12 @@ static const struct constant_table common_clear_sb_flag[] = { { }, }; -static const char *const forbidden_sb_flag[] = { - "bind", - "dev", - "exec", - "move", - "noatime", - "nodev", - "nodiratime", - "noexec", - "norelatime", - "nostrictatime", - "nosuid", - "private", - "rec", - "relatime", - "remount", - "shared", - "slave", - "strictatime", - "suid", - "unbindable", -}; - /* * Check for a common mount option that manipulates s_flags. */ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key) { unsigned int token; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(forbidden_sb_flag); i++) - if (strcmp(key, forbidden_sb_flag[i]) == 0) - return -EINVAL; token = lookup_constant(common_set_sb_flag, key, 0); if (token) { From patchwork Tue May 5 09:59:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 526231668 for ; Tue, 5 May 2020 09:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A6502075A for ; Tue, 5 May 2020 09:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YrznLMeC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728720AbgEEJ7h (ORCPT ); Tue, 5 May 2020 05:59:37 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46392 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728715AbgEEJ7e (ORCPT ); Tue, 5 May 2020 05:59:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iwN6rUp8u34Wlj1xDcqihvpusXAKoRcj4IW0NO+hiJk=; b=YrznLMeCkyiJ47quM1H3ZK5K+iQTMFdJsOPriW8HZBQne5M3xgKhIHvx3VXsGOkTVrGVbF 1udvjiaxLqBlwTlloDRCgxqsJxv98gDdOQh96HmM8pKDSB2zBV+fxRqd4a4NWkl4VMt0H7 IRYk4HUltV8OC2hlBPJd1PYtJuwTJaQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-QnGNP_hNNpmGywqa9789Qg-1; Tue, 05 May 2020 05:59:32 -0400 X-MC-Unique: QnGNP_hNNpmGywqa9789Qg-1 Received: by mail-wm1-f72.google.com with SMTP id f81so640717wmf.2 for ; Tue, 05 May 2020 02:59:31 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=iwN6rUp8u34Wlj1xDcqihvpusXAKoRcj4IW0NO+hiJk=; b=jj896c9k7i+GLyIIL8Re+mNK5FmaHnek+oLYWBiTmCdlgKeukPYKabgIs8MC9v+rgE iD7oEdpP9BVrD2IDRKOtrfTXoo5OkkmuCaIU5GhTvLsDDOc6FLSgdIggWX/ePhaf3f2y 8pPynTl4GDeIHlbDO+/uu0Aqkl64M0mrMF8ZwtgAFF8KEj7ePLedtWfFUC0FUeQl+I1q HQsf/RP/zSuPrwtj2w5v/DaGIYWLR0p7OXfXmk74eU1nT1V/kbKzIuvRS0HvOd89i8vn W/X8yxIIwQ6qxP10NnDA2wxXgTkGz1gaUfEPSTUzhuoOxkevHh2+LEdF/X5UxgyOycmg CeGw== X-Gm-Message-State: AGi0PubXEmk5Jo0idCx6kW4SICnieABe0QgvbOXcPBS67LP+0x0x8AFA FRgG9HRcoWbuxwqVnRCEK25cur77SpeVUizyvjX8jPKb07H0zRJJIDuu/fCDEBEK9p0RnX2tNrE gC87tEFXg5Xh9xlyrBCsHc99Zsw== X-Received: by 2002:a7b:cbd6:: with SMTP id n22mr2477569wmi.98.1588672770498; Tue, 05 May 2020 02:59:30 -0700 (PDT) X-Google-Smtp-Source: APiQypJfeC9g7vOlKgl6jyM9ZWJYYITo5ISdmsZhuFjOdTEXf/idZKyJK5BCIqVtFBf82lVBlKK2+Q== X-Received: by 2002:a7b:cbd6:: with SMTP id n22mr2477557wmi.98.1588672770329; Tue, 05 May 2020 02:59:30 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:29 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 11/12] vfs: don't parse "posixacl" option Date: Tue, 5 May 2020 11:59:14 +0200 Message-Id: <20200505095915.11275-12-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Unlike the others, this is _not_ a standard option accepted by mount(8). In fact SB_POSIXACL is an internal flag, and accepting MS_POSIXACL on the mount(2) interface is possibly a bug. The only filesystem that apparently wants to handle the "posixacl" option is 9p, but it has special handling of that option besides setting SB_POSIXACL. Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/fs_context.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/fs_context.c b/fs/fs_context.c index 07e09bcf256c..82019569d493 100644 --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -42,7 +42,6 @@ static const struct constant_table common_set_sb_flag[] = { { "dirsync", SB_DIRSYNC }, { "lazytime", SB_LAZYTIME }, { "mand", SB_MANDLOCK }, - { "posixacl", SB_POSIXACL }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, { }, From patchwork Tue May 5 09:59:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11528621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E15CC1668 for ; Tue, 5 May 2020 09:59:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C88F5206B9 for ; Tue, 5 May 2020 09:59:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EbRzAqqO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728725AbgEEJ7i (ORCPT ); Tue, 5 May 2020 05:59:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:60985 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728701AbgEEJ7f (ORCPT ); Tue, 5 May 2020 05:59:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588672774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L+1b61fIVNzRxmSBvn8JceIfr2zwI2o+5DSP0I2MUjY=; b=EbRzAqqOyW5fgpkNurjrDpMC6JKN3C2g/usN9tN/EOBSd622sDaBy/UZfxVB/2ywzvQpes SjHya1FKPNpk0zWXwysKUOoZkLmUWcQnoXjdfsSl0wweSJn/ixOk5GDfuaaZl6Xfoj06NV G3ivWg5+Sd9GhOWT3WrM0iExxop3pVo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-DlXe1gAiNNieto8e13FjOA-1; Tue, 05 May 2020 05:59:32 -0400 X-MC-Unique: DlXe1gAiNNieto8e13FjOA-1 Received: by mail-wm1-f70.google.com with SMTP id 72so1060763wmb.1 for ; Tue, 05 May 2020 02:59:32 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=L+1b61fIVNzRxmSBvn8JceIfr2zwI2o+5DSP0I2MUjY=; b=W32TOreeezlXAhr9oFfNOnm7M7dO7F9yaDfHPFn5XPBUsEV6m3NjBYFjMLr0YivKNK rEpWF9hCYdCJR9zSVWeHQT1+h+nU8pe3VChW2SsUETTXAQMeeSJ7TDfWdClVK36aMs0f 9ortV5gzxiCo6hFnWPHH442YNobnqy6t80fK8HtPU2LJ8sO8q3hGR+AXZEvDT34Mn4Gc h1fTFlDIdVnvlyfUuu8rkkD4LLhfNyQYhQ4E4BqfSvOXQ6CL9wffzDpgBaJEnpdsscNs Q3VWMRqyjYbzOOqP/dI2+23X0KxUVZNsXJvuGac+zBNK4QMWqlRVgy7WyjxYugkjyiXb DJTg== X-Gm-Message-State: AGi0PuYrKwp9XpJcsD//DEol4TXT5EOrdeSx9f34Tak1tAp7qqZ9VSCA Sv4miLP6zOZA+CtK7crZ37MOk2vOj226ye7/U1FCMCoHV54rqEABdOmhMfEoFaKnDhWq0iLzHQ7 pmUR8pTDZ+68Yofossn9WVRudlA== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr2255991wmi.64.1588672771523; Tue, 05 May 2020 02:59:31 -0700 (PDT) X-Google-Smtp-Source: APiQypLVtZmeTj2ECRlDJWx4w0RMnjQr8z+ceKqshfy/tdfv2YG6kV2nYhcysbYO4K2VvQijKq+SOg== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr2255978wmi.64.1588672771323; Tue, 05 May 2020 02:59:31 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id t16sm2862734wmi.27.2020.05.05.02.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 02:59:30 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 12/12] vfs: don't parse "silent" option Date: Tue, 5 May 2020 11:59:15 +0200 Message-Id: <20200505095915.11275-13-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Parsing "silent" and clearing SB_SILENT makes zero sense. Parsing "silent" and setting SB_SILENT would make a bit more sense, but apparently nobody cares. Signed-off-by: Miklos Szeredi Reviewed-by: Christoph Hellwig --- fs/fs_context.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/fs_context.c b/fs/fs_context.c index 82019569d493..7d5c5dd2b1d5 100644 --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -52,7 +52,6 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, - { "silent", SB_SILENT }, { }, }; From patchwork Wed May 13 07:45:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 11545287 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33490112C for ; Wed, 13 May 2020 07:45:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 103AA2078C for ; Wed, 13 May 2020 07:45:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Qz9tqxQZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729017AbgEMHpq (ORCPT ); Wed, 13 May 2020 03:45:46 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47548 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728905AbgEMHpp (ORCPT ); Wed, 13 May 2020 03:45:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589355943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTVKEXTYKjX2gBNpEHYaccp5hXXk/IEh6T4/2VqJQSA=; b=Qz9tqxQZWALmKPIdeR8BV0k6IRYdMPaUv3ok24fvK3LhdBUigoKti/MLjfVPjypnhbcadF Pqy2ylLcWnOiAtrP3yruXNqv1bDHAHvO5lHr/AAz9aQHFz36DMQpOoBhcB4eieblQD8XmX J0ji57jt5FEtL5RT3QNyy9lyrl61TIc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-_PaYkC9fMgG5YxX7mNOa8A-1; Wed, 13 May 2020 03:45:41 -0400 X-MC-Unique: _PaYkC9fMgG5YxX7mNOa8A-1 Received: by mail-wr1-f69.google.com with SMTP id 37so5003099wrc.4 for ; Wed, 13 May 2020 00:45:41 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HTVKEXTYKjX2gBNpEHYaccp5hXXk/IEh6T4/2VqJQSA=; b=M0yg4x/dRptSKGaQ5HCBsry007hAQQAG6r72ET9BkuwPEcL8GjpPZJu4cz/LdJik1G 2Whe4MMZj02hbQHqK4ojaLJljikBuc+NIcJWrtFNCKSv79SjyCsP+8i04i80LOAnKvp7 mrkCwKZ42qbyrOUKiyEZqTMXWW6BaFhFivmZlipMOq8btTfs8HSE7T9gG6lAzc32/QUz cnor8GydT/xXuXW7jUX1GlqGVfWtavfeCReGVtaVrKjRknJFioolEglMf4AqOdOLfPEZ BFnieYGaGGd7DUE6SIAXgWmvVSHjkB+KueBUKiUv9lcAvAA4pf7R3wgeiF5oBm1ZYJmb HnjQ== X-Gm-Message-State: AGi0PuZl4t07Qo/UhHDENMsqAvys2oOig6cK69M+vygJi15KhN236wwQ OaHZr122Nl05o4tNn4ugjKyQWRAyonvjJ8keA9EfralifLGHtNQML+IPtaBLI9GYrfV0Vad6enU cnaDCGVdU0ZCSVHy8P5XqG3rcpg== X-Received: by 2002:adf:a74b:: with SMTP id e11mr27536476wrd.99.1589355939974; Wed, 13 May 2020 00:45:39 -0700 (PDT) X-Google-Smtp-Source: APiQypJZ1wT9JSuT4RqUZrDP8ZNWGpYezSo9HONWqRJ0VK/wO4e23prC3Z6S3c1ZSS4I36EWhZjObA== X-Received: by 2002:adf:a74b:: with SMTP id e11mr27536438wrd.99.1589355939464; Wed, 13 May 2020 00:45:39 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id c17sm26518798wrn.59.2020.05.13.00.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 00:45:38 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org Subject: [13/12 PATCH] vfs: add faccessat2 syscall Date: Wed, 13 May 2020 09:45:37 +0200 Message-Id: <20200513074537.1617-1-mszeredi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200505095915.11275-1-mszeredi@redhat.com> References: <20200505095915.11275-1-mszeredi@redhat.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org POSIX defines faccessat() as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulate AT_EACCESS and AT_SYMLINK_NOFOLLOW, but AT_EACCESS emulation is broken. Add a new faccessat(2) syscall with the added flags argument and implement both flags. The value of AT_EACCESS is defined in glibc headers to be the same as AT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment. Also add AT_EMPTY_PATH support, which is not documented by POSIX, but can be useful and is trivial to implement. Signed-off-by: Miklos Szeredi --- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/internal.h | 1 - fs/open.c | 58 ++++++++++++++++----- include/linux/syscalls.h | 7 ++- include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/fcntl.h | 10 ++++ 23 files changed, 82 insertions(+), 18 deletions(-) diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl index 36d42da7466a..5ddd128d4b7a 100644 --- a/arch/alpha/kernel/syscalls/syscall.tbl +++ b/arch/alpha/kernel/syscalls/syscall.tbl @@ -477,3 +477,4 @@ # 545 reserved for clone3 547 common openat2 sys_openat2 548 common pidfd_getfd sys_pidfd_getfd +549 common faccessat2 sys_faccessat2 diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl index 4d1cf74a2caa..d5cae5ffede0 100644 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -451,3 +451,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index 803039d504de..3b859596840d 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -38,7 +38,7 @@ #define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5) #define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 439 +#define __NR_compat_syscalls 440 #endif #define __ARCH_WANT_SYS_CLONE diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index c1c61635f89c..6d95d0c8bf2f 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -883,6 +883,8 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2) #define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_faccessat2 439 +__SYSCALL(__NR_faccessat2, sys_faccessat2) /* * Please add new compat syscalls above this comment and update diff --git a/arch/ia64/kernel/syscalls/syscall.tbl b/arch/ia64/kernel/syscalls/syscall.tbl index 042911e670b8..49e325b604b3 100644 --- a/arch/ia64/kernel/syscalls/syscall.tbl +++ b/arch/ia64/kernel/syscalls/syscall.tbl @@ -358,3 +358,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl index f4f49fcb76d0..f71b1bbcc198 100644 --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -437,3 +437,4 @@ 435 common clone3 __sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/microblaze/kernel/syscalls/syscall.tbl b/arch/microblaze/kernel/syscalls/syscall.tbl index 4c67b11f9c9e..edacc4561f2b 100644 --- a/arch/microblaze/kernel/syscalls/syscall.tbl +++ b/arch/microblaze/kernel/syscalls/syscall.tbl @@ -443,3 +443,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl index 1f9e8ad636cc..f777141f5256 100644 --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -376,3 +376,4 @@ 435 n32 clone3 __sys_clone3 437 n32 openat2 sys_openat2 438 n32 pidfd_getfd sys_pidfd_getfd +439 n32 faccessat2 sys_faccessat2 diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl index c0b9d802dbf6..da8c76394e17 100644 --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -352,3 +352,4 @@ 435 n64 clone3 __sys_clone3 437 n64 openat2 sys_openat2 438 n64 pidfd_getfd sys_pidfd_getfd +439 n64 faccessat2 sys_faccessat2 diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl index ac586774c980..13280625d312 100644 --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -425,3 +425,4 @@ 435 o32 clone3 __sys_clone3 437 o32 openat2 sys_openat2 438 o32 pidfd_getfd sys_pidfd_getfd +439 o32 faccessat2 sys_faccessat2 diff --git a/arch/parisc/kernel/syscalls/syscall.tbl b/arch/parisc/kernel/syscalls/syscall.tbl index 52a15f5cd130..5a758fa6ec52 100644 --- a/arch/parisc/kernel/syscalls/syscall.tbl +++ b/arch/parisc/kernel/syscalls/syscall.tbl @@ -435,3 +435,4 @@ 435 common clone3 sys_clone3_wrapper 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl index 220ae11555f2..f833a3190822 100644 --- a/arch/powerpc/kernel/syscalls/syscall.tbl +++ b/arch/powerpc/kernel/syscalls/syscall.tbl @@ -527,3 +527,4 @@ 435 spu clone3 sys_ni_syscall 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index bd7bd3581a0f..bfdcb7633957 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -440,3 +440,4 @@ 435 common clone3 sys_clone3 sys_clone3 437 common openat2 sys_openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 sys_faccessat2 diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl index c7a30fcd135f..acc35daa1b79 100644 --- a/arch/sh/kernel/syscalls/syscall.tbl +++ b/arch/sh/kernel/syscalls/syscall.tbl @@ -440,3 +440,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl index f13615ecdecc..8004a276cb74 100644 --- a/arch/sparc/kernel/syscalls/syscall.tbl +++ b/arch/sparc/kernel/syscalls/syscall.tbl @@ -483,3 +483,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 54581ac671b4..d8f8a1a69ed1 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -442,3 +442,4 @@ 435 i386 clone3 sys_clone3 437 i386 openat2 sys_openat2 438 i386 pidfd_getfd sys_pidfd_getfd +439 i386 faccessat2 sys_faccessat2 diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index 37b844f839bc..78847b32e137 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -359,6 +359,7 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/arch/xtensa/kernel/syscalls/syscall.tbl b/arch/xtensa/kernel/syscalls/syscall.tbl index 85a9ab1bc04d..69d0d73876b3 100644 --- a/arch/xtensa/kernel/syscalls/syscall.tbl +++ b/arch/xtensa/kernel/syscalls/syscall.tbl @@ -408,3 +408,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 diff --git a/fs/internal.h b/fs/internal.h index aa5d45524e87..0d467e32dd7e 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -126,7 +126,6 @@ extern struct open_how build_open_how(int flags, umode_t mode); extern int build_open_flags(const struct open_how *how, struct open_flags *op); long do_sys_ftruncate(unsigned int fd, loff_t length, int small); -long do_faccessat(int dfd, const char __user *filename, int mode); int do_fchmodat(int dfd, const char __user *filename, umode_t mode); int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, int flag); diff --git a/fs/open.c b/fs/open.c index 719b320ede52..6f3cdf109ec0 100644 --- a/fs/open.c +++ b/fs/open.c @@ -345,21 +345,14 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) * We do this by temporarily clearing all FS-related capabilities and * switching the fsuid/fsgid around to the real ones. */ -long do_faccessat(int dfd, const char __user *filename, int mode) +static const struct cred *access_override_creds(void) { const struct cred *old_cred; struct cred *override_cred; - struct path path; - struct inode *inode; - int res; - unsigned int lookup_flags = LOOKUP_FOLLOW; - - if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ - return -EINVAL; override_cred = prepare_creds(); if (!override_cred) - return -ENOMEM; + return NULL; override_cred->fsuid = override_cred->uid; override_cred->fsgid = override_cred->gid; @@ -394,6 +387,38 @@ long do_faccessat(int dfd, const char __user *filename, int mode) override_cred->non_rcu = 1; old_cred = override_creds(override_cred); + + /* override_cred() gets its own ref */ + put_cred(override_cred); + + return old_cred; +} + +long do_faccessat(int dfd, const char __user *filename, int mode, int flags) +{ + const struct cred *old_cred = NULL; + struct path path; + struct inode *inode; + int res; + unsigned int lookup_flags = LOOKUP_FOLLOW; + + if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ + return -EINVAL; + + if (flags & ~(AT_EACCESS | AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) + return -EINVAL; + + if (flags & AT_SYMLINK_NOFOLLOW) + lookup_flags &= ~LOOKUP_FOLLOW; + if (flags & AT_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; + + if (!(flags & AT_EACCESS)) { + old_cred = access_override_creds(); + if (!old_cred) + return -ENOMEM; + } + retry: res = user_path_at(dfd, filename, lookup_flags, &path); if (res) @@ -435,19 +460,26 @@ long do_faccessat(int dfd, const char __user *filename, int mode) goto retry; } out: - revert_creds(old_cred); - put_cred(override_cred); + if (old_cred) + revert_creds(old_cred); + return res; } SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) { - return do_faccessat(dfd, filename, mode); + return do_faccessat(dfd, filename, mode, 0); +} + +SYSCALL_DEFINE4(faccessat2, int, dfd, const char __user *, filename, int, mode, + int, flags) +{ + return do_faccessat(dfd, filename, mode, flags); } SYSCALL_DEFINE2(access, const char __user *, filename, int, mode) { - return do_faccessat(AT_FDCWD, filename, mode); + return do_faccessat(AT_FDCWD, filename, mode, 0); } int ksys_chdir(const char __user *filename) diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 1815065d52f3..baec24782301 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -428,6 +428,8 @@ asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length); #endif asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len); asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode); +asmlinkage long sys_faccessat2(int dfd, const char __user *filename, int mode, + int flags); asmlinkage long sys_chdir(const char __user *filename); asmlinkage long sys_fchdir(unsigned int fd); asmlinkage long sys_chroot(const char __user *filename); @@ -1333,11 +1335,12 @@ static inline int ksys_chmod(const char __user *filename, umode_t mode) return do_fchmodat(AT_FDCWD, filename, mode); } -extern long do_faccessat(int dfd, const char __user *filename, int mode); +extern long do_faccessat(int dfd, const char __user *filename, int mode, + int flags); static inline long ksys_access(const char __user *filename, int mode) { - return do_faccessat(AT_FDCWD, filename, mode); + return do_faccessat(AT_FDCWD, filename, mode, 0); } extern int do_fchownat(int dfd, const char __user *filename, uid_t user, diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 3a3201e4618e..f4a01305d9a6 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2) #define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_faccessat2 439 +__SYSCALL(__NR_faccessat2, sys_faccessat2) #undef __NR_syscalls -#define __NR_syscalls 439 +#define __NR_syscalls 440 /* * 32 bit systems traditionally used different diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index ca88b7bce553..2f86b2ad6d7e 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -84,10 +84,20 @@ #define DN_ATTRIB 0x00000020 /* File changed attibutes */ #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ +/* + * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is + * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to + * unlinkat. The two functions do completely different things and therefore, + * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to + * faccessat would be undefined behavior and thus treating it equivalent to + * AT_EACCESS is valid undefined behavior. + */ #define AT_FDCWD -100 /* Special value used to indicate openat should use the current working directory. */ #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ +#define AT_EACCESS 0x200 /* Test access permitted for + effective IDs, not real IDs. */ #define AT_REMOVEDIR 0x200 /* Remove directory instead of unlinking file. */ #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */