From patchwork Thu Nov 15 18:45:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10684849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9234B13BF for ; Thu, 15 Nov 2018 18:46:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 841882CF57 for ; Thu, 15 Nov 2018 18:46:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 789DC2CF59; Thu, 15 Nov 2018 18:46:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 18A0E2CF57 for ; Thu, 15 Nov 2018 18:46:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388830AbeKPEy7 (ORCPT ); Thu, 15 Nov 2018 23:54:59 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34944 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbeKPEy5 (ORCPT ); Thu, 15 Nov 2018 23:54:57 -0500 Received: by mail-wr1-f67.google.com with SMTP id 96so5440189wrb.2; Thu, 15 Nov 2018 10:46:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=39sqUJXoVTyhcy949zdokoRUQa5EcmK8aLZP2t7y09Q=; b=Kkqf0jwujwwOeCg5TUZpUaDVR4pMKSpivUaixF+O2/314b5mMhlhteKFzSTxGf2LJx Y+5/U0hIHWTllwGmFC28Ii2kYETNAc8FvmRdCv83jpSeNe8s4/u0R2rYv+O979Vaw4rN 9FNFzVZ/dSPnHrqgjXhC6UUQrN0qjzanzNgl1jdzFYOLboTlkWyfLon7GtMDTgkrvstn LtBtAhnLaszFxFOjEojGoOc1jCq9I9fS+dhQOCI7NZ8kEMXQKTHz2fzuGqsc2VimTC8l H53EAM3oUr09vyle3NNupzUkCDLLipkhK+OAttsd4AebtkmJorNCWgTlayJ/0ECtxwY+ Bfrw== 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; bh=39sqUJXoVTyhcy949zdokoRUQa5EcmK8aLZP2t7y09Q=; b=WzdACCnrv172TrABoVBm0FrPRcKBaz5whl+jajZu4gyTD814+wdFW8l2Qd5kllufKx lYBmgQ4YCxsNQ9qhwlb00YdtdygJZPGyxHTBNlUg41Afaj3hkYqqAOj2pI9AsunXj0Kt AK8RtywSwazRDsilOxT88ESKAnfz2HjHQBE6jEN185FSla18DyJhpCOUGm15U0wWdaVo LwdN1XTrYjkzWaSdCizneI7Ca4mZJdlXkCa7MuoqOKZ0Dd4Jj6JOe8y5cdDKWLxiNawx XUo/NRP8k/chaD5ID3o3DZl3SvS+3VC10sMbW4TGatpnNFQBaOMwrg60X/DjFtrTfUky 9Ybw== X-Gm-Message-State: AGRZ1gIuNf+6ydMnabxaoheK7+4kXI8oJOp5qC0ZtxtoOpBxRuWnXolG qmOzfi06LrCWm9F3rQbhVd8= X-Google-Smtp-Source: AJdET5ejcbLuZiHFD1gyHrckbSiB4GdDM/NSRyXtuUIgf40kmcmSvllPdEVzYQqKDZmhtBFkYSvW7A== X-Received: by 2002:adf:bc0c:: with SMTP id s12-v6mr6744273wrg.255.1542307559456; Thu, 15 Nov 2018 10:45:59 -0800 (PST) Received: from localhost.localdomain ([37.46.46.74]) by smtp.gmail.com with ESMTPSA id s1sm13976327wro.9.2018.11.15.10.45.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 10:45:58 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v2 6/9] fanotify: enable FAN_REPORT_FID init flag Date: Thu, 15 Nov 2018 20:45:41 +0200 Message-Id: <20181115184544.30681-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181115184544.30681-1-amir73il@gmail.com> References: <20181115184544.30681-1-amir73il@gmail.com> 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 When setting up an fanotify listener, user may request to get fid information in event instead of an open file descriptor. The fid obtained with event on a watched object contains the file handle returned by name_to_handle_at(2) and fsid returned by statfs(2). Both name_to_handle_at(2) and statfs(2) are allowed for unprivileged users that have access to a given path, so we also allow an unprivileged listener to get fid information, because with unprivileged listener, users can only set marks on inode objects they have read access to. When setting a mark, we need to make sure that the filesystem supports file handles, so user can use name_to_handle_at(2) to compare fid returned with event to the file handle of watched objects. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 17 ++++++++++++++++- include/linux/fanotify.h | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 7e38d7a1854b..8ded9b5c0e76 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -942,6 +943,19 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (ret) goto fput_and_out; + /* + * We need to make sure whether the file system supports at least + * encoding a file handle so user can use name_to_handle_at() to + * compare fid returned with event to the file handle of watched + * objects. However, name_to_handle_at() requires that filesystem + * supports decoding file handles as well. + */ + ret = -EOPNOTSUPP; + if (FAN_GROUP_FLAG(group, FAN_REPORT_FID) && + (!path.dentry->d_sb->s_export_op || + !path.dentry->d_sb->s_export_op->fh_to_dentry)) + goto path_put_and_out; + /* inode held in place by reference to path; group by fget on fd */ if (mark_type == FAN_MARK_INODE) inode = path.dentry->d_inode; @@ -970,6 +984,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, ret = -EINVAL; } +path_put_and_out: path_put(&path); fput_and_out: fdput(f); @@ -1006,7 +1021,7 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark, */ static int __init fanotify_user_setup(void) { - BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 7); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 8); BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 9e2142795335..f59be967f72b 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -19,7 +19,7 @@ FAN_CLASS_PRE_CONTENT) #define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ - FAN_REPORT_TID | \ + FAN_REPORT_TID | FAN_REPORT_FID | \ FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)