From patchwork Mon Dec 11 06:04:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10104267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8240F60235 for ; Mon, 11 Dec 2017 06:05:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 737BF27E71 for ; Mon, 11 Dec 2017 06:05:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685B32941C; Mon, 11 Dec 2017 06:05:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 1AAEE27E71 for ; Mon, 11 Dec 2017 06:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752473AbdLKGEu (ORCPT ); Mon, 11 Dec 2017 01:04:50 -0500 Received: from mx2.suse.de ([195.135.220.15]:46400 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752346AbdLKGEr (ORCPT ); Mon, 11 Dec 2017 01:04:47 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CBDA1AAB5; Mon, 11 Dec 2017 06:04:45 +0000 (UTC) From: NeilBrown To: Linus Torvalds , Al Viro Date: Mon, 11 Dec 2017 17:04:05 +1100 Subject: [PATCH 4/4] fhandle: Improve error responses in name_to_handle_at() Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, Amir Goldstein , lkml , Lennart Poettering Message-ID: <151297224523.7818.12267549679803980398.stgit@noble> In-Reply-To: <151297214390.7818.7216826079527521005.stgit@noble> References: <151297214390.7818.7216826079527521005.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1/ Always return the mnt_id, even if some other error occurs. It can be useful without the file handle. An application can initialise the memory to, e.g. -1 and if there is some other value after name_to_handle_at() returns, then it is a valid mnt_id. If the value is unchanged, then the kernel does not have this patch. 2/ Don't return -EINVAL if the requested handle_bytes is larger than MAX_HANDLE_SZ. There is no need for an error and it causes unnecessary behavior change in the kernel ever needs to increase MAX_HANDLE_SZ. Simple limit handle_bytes to MAX_HANDLE_SZ silently. Signed-off-by: NeilBrown --- fs/fhandle.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/fhandle.c b/fs/fhandle.c index 0ace128f5d23..04afffaeb742 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -23,9 +23,16 @@ static long do_sys_name_to_handle(struct path *path, int handle_dwords, handle_bytes; struct file_handle *handle = NULL; + /* + * Always return the mnt_id, it might be useful even + * without the file handle + */ + if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id, + sizeof(*mnt_id))) + return -EFAULT; /* * We need to make sure whether the file system - * support decoding of the file handle + * supports decoding of the file handle. */ if (!path->dentry->d_sb->s_export_op || !path->dentry->d_sb->s_export_op->fh_to_dentry) @@ -35,7 +42,7 @@ static long do_sys_name_to_handle(struct path *path, return -EFAULT; if (f_handle.handle_bytes > MAX_HANDLE_SZ) - return -EINVAL; + f_handle.handle_bytes = MAX_HANDLE_SZ; handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes, GFP_KERNEL); @@ -68,10 +75,7 @@ static long do_sys_name_to_handle(struct path *path, retval = -EOVERFLOW; } else retval = 0; - /* copy the mount id */ - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id, - sizeof(*mnt_id)) || - copy_to_user(ufh, handle, + if (copy_to_user(ufh, handle, sizeof(struct file_handle) + handle_bytes)) retval = -EFAULT; kfree(handle);