From patchwork Thu Apr 16 22:12:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493907 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 4EA15174A for ; Thu, 16 Apr 2020 22:15:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 358992223F for ; Thu, 16 Apr 2020 22:15:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075304; bh=UBxOfKwmooiVMIBZRcKC/SzyfEfO3jdrx0sJu4y+Nmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BtYdgPE90qn2Yzv6tDSnPqromYDwzLpAzoyDJiUskq3i83P4coIj+DHYWEaZZqIOK YXDRru84ccG6TkiKIz1oH19eTpFiYXvWHWSOAkn+YAhAwY2Pmh+t1GIH8vLxl4QSb1 4qxFOOXbm40+1s57Sq3DCzod70Fie+IJy9AXPrJ8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbgDPWPC (ORCPT ); Thu, 16 Apr 2020 18:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:54128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729164AbgDPWPB (ORCPT ); Thu, 16 Apr 2020 18:15:01 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9EC29221F9; Thu, 16 Apr 2020 22:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075300; bh=UBxOfKwmooiVMIBZRcKC/SzyfEfO3jdrx0sJu4y+Nmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzBDqnQD3DblWJL/zo55P51ilF6bGp2azZMYek7e7uJzZO3Jn4yDuqJWBYUrUmwxp +9Q4Xd/qM36WuBFCaaALBoRXxSiSdTYpUWnmd4Z9VgVLVP5vBWG0mlCRxz0kcsHdxO MW1xVd9780NnYzzkWfgACPWRHiJT9HGljQ6iXuYE= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/7] mountd: Add a helper nfsd_path_statfs64() for uuid_by_path() Date: Thu, 16 Apr 2020 18:12:46 -0400 Message-Id: <20200416221252.82102-2-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-1-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Ensure uuid_by_path() works correctly when 'rootdir' is set in the [exports] section of nfs.conf. Signed-off-by: Trond Myklebust --- support/include/nfsd_path.h | 5 +++++ support/misc/nfsd_path.c | 43 +++++++++++++++++++++++++++++++++++++ utils/mountd/cache.c | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h index b42416bbff58..8331ff96a277 100644 --- a/support/include/nfsd_path.h +++ b/support/include/nfsd_path.h @@ -6,6 +6,8 @@ #include +struct statfs64; + void nfsd_path_init(void); const char * nfsd_path_nfsd_rootdir(void); @@ -15,6 +17,9 @@ char * nfsd_path_prepend_dir(const char *dir, const char *pathname); int nfsd_path_stat(const char *pathname, struct stat *statbuf); int nfsd_path_lstat(const char *pathname, struct stat *statbuf); +int nfsd_path_statfs64(const char *pathname, + struct statfs64 *statbuf); + char * nfsd_realpath(const char *path, char *resolved_path); ssize_t nfsd_path_read(int fd, char *buf, size_t len); diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index f078a668fb8f..ab6c98dbe395 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,48 @@ nfsd_path_lstat(const char *pathname, struct stat *statbuf) return nfsd_run_stat(nfsd_wq, nfsd_lstatfunc, pathname, statbuf); } +struct nfsd_statfs64_data { + const char *pathname; + struct statfs64 *statbuf; + int ret; + int err; +}; + +static void +nfsd_statfs64func(void *data) +{ + struct nfsd_statfs64_data *d = data; + + d->ret = statfs64(d->pathname, d->statbuf); + if (d->ret < 0) + d->err = errno; +} + +static int +nfsd_run_statfs64(struct xthread_workqueue *wq, + const char *pathname, + struct statfs64 *statbuf) +{ + struct nfsd_statfs64_data data = { + pathname, + statbuf, + 0, + 0 + }; + xthread_work_run_sync(wq, nfsd_statfs64func, &data); + if (data.ret < 0) + errno = data.err; + return data.ret; +} + +int +nfsd_path_statfs64(const char *pathname, struct statfs64 *statbuf) +{ + if (!nfsd_wq) + return statfs64(pathname, statbuf); + return nfsd_run_statfs64(nfsd_wq, pathname, statbuf); +} + struct nfsd_realpath_data { const char *pathname; char *resolved; diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 8f54e37b7936..7d8657c91323 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -352,7 +352,7 @@ static int uuid_by_path(char *path, int type, size_t uuidlen, char *uuid) const char *val; int rc; - rc = statfs64(path, &st); + rc = nfsd_path_statfs64(path, &st); if (type == 0 && rc == 0) { const unsigned long *bad; From patchwork Thu Apr 16 22:12:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493909 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 48D401392 for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30FE622245 for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075305; bh=T4yeFO6a2Xdolflm5Sk9634oTQJvbzJs/jNvsRwN3WQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=aFJSXzt8nkoeVTdftCJr6W9GGlRzYePTOCIpsogB/LVkaCjzF3ejJjn69XRO6ugtE lgW2n6f1HhdWT6VX4LkaH2QPHfR+YMnlXkcQkxC00Z9KpOA1kwysSAh/vi+ZAfh98C 7C//1xNTQ2f8v853VSoN6OWWWQ7VvfBbm2g1iu9g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728839AbgDPWPD (ORCPT ); Thu, 16 Apr 2020 18:15:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:54148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729187AbgDPWPB (ORCPT ); Thu, 16 Apr 2020 18:15:01 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2CF7622202; Thu, 16 Apr 2020 22:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075301; bh=T4yeFO6a2Xdolflm5Sk9634oTQJvbzJs/jNvsRwN3WQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iGwuRcQKsVWEt4ewo6qZk9fAhzxWTd3O9O5+X9l/oALtWLfS6xgBIyyuebHqwyABu FBfo8i6Iebztpw06608cynpDWHhXiL13nhhdVKVH59D2STRSa/TmmSMc8Fwpxd1j9Q r5SEVSZxPACtw22bmA6sBgGa6aRcMVih96L91N0A= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/7] nfsd: Support running nfsd_name_to_handle_at() in the root jail Date: Thu, 16 Apr 2020 18:12:47 -0400 Message-Id: <20200416221252.82102-3-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-2-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust When running nfsd_name_to_handle_at(), we usually want to see the same namespace as knfsd, so add helpers. Signed-off-by: Trond Myklebust --- support/include/nfsd_path.h | 4 +++ support/misc/nfsd_path.c | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/support/include/nfsd_path.h b/support/include/nfsd_path.h index 8331ff96a277..3b73aadd8af7 100644 --- a/support/include/nfsd_path.h +++ b/support/include/nfsd_path.h @@ -6,6 +6,7 @@ #include +struct file_handle; struct statfs64; void nfsd_path_init(void); @@ -25,4 +26,7 @@ char * nfsd_realpath(const char *path, char *resolved_path); ssize_t nfsd_path_read(int fd, char *buf, size_t len); ssize_t nfsd_path_write(int fd, const char *buf, size_t len); +int nfsd_name_to_handle_at(int fd, const char *path, + struct file_handle *fh, + int *mount_id, int flags); #endif diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index ab6c98dbe395..1f6dfd4b642b 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include "xmalloc.h" #include "xlog.h" #include "xstat.h" +#include "nfslib.h" #include "nfsd_path.h" #include "workqueue.h" @@ -340,3 +342,67 @@ nfsd_path_write(int fd, const char *buf, size_t len) return write(fd, buf, len); return nfsd_run_write(nfsd_wq, fd, buf, len); } + +#if defined(HAVE_NAME_TO_HANDLE_AT) +struct nfsd_handle_data { + int fd; + const char *path; + struct file_handle *fh; + int *mount_id; + int flags; + int ret; + int err; +}; + +static void +nfsd_name_to_handle_func(void *data) +{ + struct nfsd_handle_data *d = data; + + d->ret = name_to_handle_at(d->fd, d->path, + d->fh, d->mount_id, d->flags); + if (d->ret < 0) + d->err = errno; +} + +static int +nfsd_run_name_to_handle_at(struct xthread_workqueue *wq, + int fd, const char *path, struct file_handle *fh, + int *mount_id, int flags) +{ + struct nfsd_handle_data data = { + fd, + path, + fh, + mount_id, + flags, + 0, + 0 + }; + + xthread_work_run_sync(wq, nfsd_name_to_handle_func, &data); + if (data.ret < 0) + errno = data.err; + return data.ret; +} + +int +nfsd_name_to_handle_at(int fd, const char *path, struct file_handle *fh, + int *mount_id, int flags) +{ + if (!nfsd_wq) + return name_to_handle_at(fd, path, fh, mount_id, flags); + + return nfsd_run_name_to_handle_at(nfsd_wq, fd, path, fh, + mount_id, flags); +} +#else +int +nfsd_name_to_handle_at(int UNUSED(fd), const char *UNUSED(path), + struct file_handle *UNUSED(fh), + int *UNUSED(mount_id), int UNUSED(flags)) +{ + errno = ENOSYS; + return -1; +} +#endif From patchwork Thu Apr 16 22:12:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493919 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 6A37A1392 for ; Thu, 16 Apr 2020 22:15:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51FBD218AC for ; Thu, 16 Apr 2020 22:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075309; bh=XcOH0u56sQC3dCT24oQ04hjxmbOtq4sKYGsePtObZeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jZFhVoB0zyrIoPDYcYzdwe0a4uvgjEBrYM4hKNno7vTJ2IjTCJUCx61/pKBy75RBO h1CEzpREoJ9qg136tG18purHKa2OyX2G58jEON5FM260vkQE38A+KJ9aiWYkkJA2EI 0ygRmNUQoPJRgZVglVvIZD51smpUMxUB0BpHQgoQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729199AbgDPWPF (ORCPT ); Thu, 16 Apr 2020 18:15:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729193AbgDPWPC (ORCPT ); Thu, 16 Apr 2020 18:15:02 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB9072223F; Thu, 16 Apr 2020 22:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075302; bh=XcOH0u56sQC3dCT24oQ04hjxmbOtq4sKYGsePtObZeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qI//DXS3Dl+Ay6ociqIRM5DeFZ6AavbPMvTPyUaWUmEoT+r3ALknm60R0zkV4V3a+ MztMA31gOCbCmn8q1j2f8+GF1ZHWY40f/lWymgFSO4/qqyibToBfhEwnMhaZG3EBgi xB5CC2vWn9ri+VhdF+qcoJg3yR1Ay8alrl84rSOQ= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/7] mountd: Fix up path checking helper same_path() Date: Thu, 16 Apr 2020 18:12:48 -0400 Message-Id: <20200416221252.82102-4-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-3-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> <20200416221252.82102-3-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Convert 'same_path()' so that it works when 'rootdir' is set in the [exports] section of nfs.conf. Signed-off-by: Trond Myklebust --- utils/mountd/cache.c | 83 +++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 7d8657c91323..94e9e44b46b9 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -72,6 +72,18 @@ static ssize_t cache_write(int fd, const char *buf, size_t len) return nfsd_path_write(fd, buf, len); } +static bool path_lookup_error(int err) +{ + switch (err) { + case ELOOP: + case ENAMETOOLONG: + case ENOENT: + case ENOTDIR: + return 1; + } + return 0; +} + /* * Support routines for text-based upcalls. * Fields are separated by spaces. @@ -430,23 +442,9 @@ static inline int count_slashes(char *p) return cnt; } -static int same_path(char *child, char *parent, int len) +#if defined(HAVE_STRUCT_FILE_HANDLE) +static int check_same_path_by_handle(const char *child, const char *parent) { - static char p[PATH_MAX]; - struct stat sc, sp; - - if (len <= 0) - len = strlen(child); - strncpy(p, child, len); - p[len] = 0; - if (strcmp(p, parent) == 0) - return 1; - - /* If number of '/' are different, they must be different */ - if (count_slashes(p) != count_slashes(parent)) - return 0; - -#if defined(HAVE_NAME_TO_HANDLE_AT) && defined(HAVE_STRUCT_FILE_HANDLE) struct { struct file_handle fh; unsigned char handle[128]; @@ -455,13 +453,17 @@ static int same_path(char *child, char *parent, int len) fchild.fh.handle_bytes = 128; fparent.fh.handle_bytes = 128; - if (name_to_handle_at(AT_FDCWD, p, &fchild.fh, &mnt_child, 0) != 0) { - if (errno == ENOSYS) - goto fallback; - return 0; + + /* This process should have the CAP_DAC_READ_SEARCH capability */ + if (nfsd_name_to_handle_at(AT_FDCWD, child, &fchild.fh, &mnt_child, 0) < 0) + return -1; + if (nfsd_name_to_handle_at(AT_FDCWD, parent, &fparent.fh, &mnt_parent, 0) < 0) { + /* If the child resolved, but the parent did not, they differ */ + if (path_lookup_error(errno)) + return 0; + /* Otherwise, we just don't know */ + return -1; } - if (name_to_handle_at(AT_FDCWD, parent, &fparent.fh, &mnt_parent, 0) != 0) - return 0; if (mnt_child != mnt_parent || fchild.fh.handle_bytes != fparent.fh.handle_bytes || @@ -471,14 +473,24 @@ static int same_path(char *child, char *parent, int len) return 0; return 1; -fallback: +} +#else +static int check_same_path_by_handle(const char *child, const char *parent) +{ + errno = ENOSYS; + return -1; +} #endif +static int check_same_path_by_inode(const char *child, const char *parent) +{ + struct stat sc, sp; + /* This is nearly good enough. However if a directory is * bind-mounted in two places and both are exported, it * could give a false positive */ - if (nfsd_path_lstat(p, &sc) != 0) + if (nfsd_path_lstat(child, &sc) != 0) return 0; if (nfsd_path_lstat(parent, &sp) != 0) return 0; @@ -490,6 +502,29 @@ fallback: return 1; } +static int same_path(char *child, char *parent, int len) +{ + static char p[PATH_MAX]; + int err; + + if (len <= 0) + len = strlen(child); + strncpy(p, child, len); + p[len] = 0; + if (strcmp(p, parent) == 0) + return 1; + + /* If number of '/' are different, they must be different */ + if (count_slashes(p) != count_slashes(parent)) + return 0; + + /* Try to use filehandle approach before falling back to stat() */ + err = check_same_path_by_handle(p, parent); + if (err != -1) + return err; + return check_same_path_by_inode(p, parent); +} + static int is_subdirectory(char *child, char *parent) { /* Check is child is strictly a subdirectory of From patchwork Thu Apr 16 22:12:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493911 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 68128186E for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E6562224E for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075305; bh=0gdPE40FK1apLhWsEYvg0xL+rWdC2zhl3BTc08Bc+tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PpEjbN0C1S0mfC4wcoeE9o8loWmixkajEWFwCJ9p/ImfZpUiPRbKYGW+ateL3xrHe Apa5f1axBzNEe4RoOuhGZF7HHhJzYTKZkqIax0A7oQfSHqihRj/Yjqv4e1p19kpgfR gVVwxn2760Lby6ytztABhqHdJTXovVw4TypQvbu8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729197AbgDPWPE (ORCPT ); Thu, 16 Apr 2020 18:15:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:54210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729164AbgDPWPC (ORCPT ); Thu, 16 Apr 2020 18:15:02 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31F3D2220A; Thu, 16 Apr 2020 22:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075302; bh=0gdPE40FK1apLhWsEYvg0xL+rWdC2zhl3BTc08Bc+tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fcyjMcELf+I8QOQ+03XECuu3PdVmz44ZtrovCBYkFItOiUkK7oeooz+/KIhoUl9dU jf1hXuBjQhsRh9SBCSQ/A6I5oKyPvdVt0apsWOYZBgr3WD36YEeypOcXKUmfNs/wSD OGUAusQMSiEA4Ji2egxgNT8idQvVXWmzY8BtCHZM= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/7] Fix autoconf probe for 'struct nfs_filehandle' Date: Thu, 16 Apr 2020 18:12:49 -0400 Message-Id: <20200416221252.82102-5-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-4-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> <20200416221252.82102-3-trondmy@kernel.org> <20200416221252.82102-4-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust It was failing because fcntl.h is not one of the standard includes. Signed-off-by: Trond Myklebust --- configure.ac | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 00b32800c526..df88e58fd0d4 100644 --- a/configure.ac +++ b/configure.ac @@ -531,7 +531,12 @@ AC_TYPE_PID_T AC_TYPE_SIZE_T AC_HEADER_TIME AC_STRUCT_TM -AC_CHECK_TYPES([struct file_handle]) +AC_CHECK_TYPES([struct file_handle], [], [], [[ + #define _GNU_SOURCE + #include + #include + #include + ]]) dnl ************************************************************* dnl Check for functions From patchwork Thu Apr 16 22:12:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493915 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 808BA174A for ; Thu, 16 Apr 2020 22:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F51E22202 for ; Thu, 16 Apr 2020 22:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075306; bh=L9CuUF9Eo7o6IB4MaJhkwj9cQWCykiYgn3y2kq3cvk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=DEm+15nUIc8WE5rjbdM7VDKCDy3gMQndds26ZS7J/3cKN3+DBxhSVMfP3B8E9CZij 0+FfzE8kozxxyn+dy3HRu1LQNPkeKSicnYPHQqOws5HIxeJz2TjUUgeLoXS0xw0feN Wl1TfSyikax3F5K/rFbD76aMKZ8bMx2g1vKHr82Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729187AbgDPWPE (ORCPT ); Thu, 16 Apr 2020 18:15:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:54222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729197AbgDPWPD (ORCPT ); Thu, 16 Apr 2020 18:15:03 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3D982222D; Thu, 16 Apr 2020 22:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075303; bh=L9CuUF9Eo7o6IB4MaJhkwj9cQWCykiYgn3y2kq3cvk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aVQWMFK7F8fCTBEprh63MlAN7vA3Jw2r/YgFA7Wiy7sJ8kXsoa8Kz53bppO4Sgz3h 5te1SjBx+uewiNg2SIZyNValIhtJrF+rDtjMTkoM4ZHzyRg7f4TFYc/XJhOf9Mv25S bGUVvtz8hL7Sstfad/3GJLOKKiIc6lL2AT1qm/r8= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 5/7] mountd: Ensure dump_to_cache() sets errno appropriately Date: Thu, 16 Apr 2020 18:12:50 -0400 Message-Id: <20200416221252.82102-6-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-5-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> <20200416221252.82102-3-trondmy@kernel.org> <20200416221252.82102-4-trondmy@kernel.org> <20200416221252.82102-5-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust cache_write() will set errno if it returns -1, so that callers can handle errors appropriately, however dump_to_cache() needs to do so too. Signed-off-by: Trond Myklebust --- utils/mountd/cache.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 94e9e44b46b9..0f323226b12a 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -936,12 +936,13 @@ static void write_secinfo(char **bp, int *blen, struct exportent *ep, int flag_m } -static int dump_to_cache(int f, char *buf, int buflen, char *domain, +static int dump_to_cache(int f, char *buf, int blen, char *domain, char *path, struct exportent *exp, int ttl) { char *bp = buf; - int blen = buflen; time_t now = time(0); + size_t buflen; + ssize_t err; if (ttl <= 1) ttl = DEFAULT_TTL; @@ -974,8 +975,18 @@ static int dump_to_cache(int f, char *buf, int buflen, char *domain, } else qword_adduint(&bp, &blen, now + ttl); qword_addeol(&bp, &blen); - if (blen <= 0) return -1; - if (cache_write(f, buf, bp - buf) != bp - buf) return -1; + if (blen <= 0) { + errno = ENOBUFS; + return -1; + } + buflen = bp - buf; + err = cache_write(f, buf, buflen); + if (err < 0) + return err; + if ((size_t)err != buflen) { + errno = ENOSPC; + return -1; + } return 0; } From patchwork Thu Apr 16 22:12:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493913 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 ED8C91392 for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC8EF2222D for ; Thu, 16 Apr 2020 22:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075305; bh=3aUFRrpZcE/s1KgidxE52RylYFuRQiFUfWiqJcLIGjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dsj7yDGMG0nAZlaEY+1slbEMUPqwkEING4zNeGlEsilK/1FVhc/xIB0hvGkPfPaUE o/ISGqn9nlRqH99NKfzckmosEslhTC9pZj/dvp2XQ0lEVOTOHVXvshfzmK0nCAt4PC r8CzDpc+v7kwkvh3aV7B8kUqa33s+sMIat8QqW3o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729164AbgDPWPE (ORCPT ); Thu, 16 Apr 2020 18:15:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:54234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729199AbgDPWPD (ORCPT ); Thu, 16 Apr 2020 18:15:03 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B3C4221F9; Thu, 16 Apr 2020 22:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075303; bh=3aUFRrpZcE/s1KgidxE52RylYFuRQiFUfWiqJcLIGjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3IgAwR42Ba40tyMNX0H++hTLOh6X5tbjjpcB5iKt+8RzXpnPfDMz8H+T60m5J4K9 S+J+TUQ4WJZlZYwfq4epGcvCB38JbQOZ/sh9YMFgoYr7pnkHeRxG/RpHLiZRoabW41 sZz3bBAtwNC7XLnzq8Un5A5jbXPRGyUObp27TZXM= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() Date: Thu, 16 Apr 2020 18:12:51 -0400 Message-Id: <20200416221252.82102-7-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-6-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> <20200416221252.82102-3-trondmy@kernel.org> <20200416221252.82102-4-trondmy@kernel.org> <20200416221252.82102-5-trondmy@kernel.org> <20200416221252.82102-6-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust In nfsd_fh(), if the error returned by the downcall is transient, then we should ignore it. Only reject the export if the filesystem path is truly not exportable. This fixes a case where we can see spurious NFSERR_STALE errors being returned by knfsd. Signed-off-by: Trond Myklebust --- utils/mountd/cache.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 0f323226b12a..79d3ee085a90 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -843,8 +843,14 @@ static void nfsd_fh(int f) } } } - if (found && - found->e_mountpoint && + + if (!found) { + /* The missing dev could be what we want, so just be + * quiet rather than returning stale yet + */ + if (dev_missing) + goto out; + } else if (found->e_mountpoint && !is_mountpoint(found->e_mountpoint[0]? found->e_mountpoint: found->e_path)) { @@ -855,17 +861,12 @@ static void nfsd_fh(int f) */ /* FIXME we need to make sure we re-visit this later */ goto out; + } else if (cache_export_ent(buf, sizeof(buf), dom, found, found_path) < 0) { + if (!path_lookup_error(errno)) + goto out; + /* The kernel is saying the path is unexportable */ + found = NULL; } - if (!found && dev_missing) { - /* The missing dev could be what we want, so just be - * quite rather than returning stale yet - */ - goto out; - } - - if (found) - if (cache_export_ent(buf, sizeof(buf), dom, found, found_path) < 0) - found = 0; bp = buf; blen = sizeof(buf); qword_add(&bp, &blen, dom); From patchwork Thu Apr 16 22:12:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11493917 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 6647A174A for ; Thu, 16 Apr 2020 22:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E66A22202 for ; Thu, 16 Apr 2020 22:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075308; bh=TxjuFdblTE83Xqokj0V9LEHx2yuzl+bFcMMPFlaotck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mpSWAsYnHsmyzVhNmSNOsNN3sAqD2XMLO5Bfji5+qoHEqbrUnYiFZSq33PDlTiyI5 S/UsMUWtshW3sPRAUZ8nGougzSZx4ugdoTeUyW7tsroKe2IT6Sd+sSIlNq665DlpF+ 6zpNDrNNezil6B8/ES1+iXRrsTAi+bY5Ao4dlbro= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729193AbgDPWPF (ORCPT ); Thu, 16 Apr 2020 18:15:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:54246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729205AbgDPWPE (ORCPT ); Thu, 16 Apr 2020 18:15:04 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB8B022202; Thu, 16 Apr 2020 22:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587075304; bh=TxjuFdblTE83Xqokj0V9LEHx2yuzl+bFcMMPFlaotck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MzPrOadT3SnE/NcE+lUyA7xCwtwrGCg+R3HLk793mYyy3IEwspcHvR2cbmplhwe5f P/vhcKkofK4qNNqs6QixRJqOhaQZdN8KC9ebZ8Fsjx54wtgow3xiqC0k44GatnA6Rp 0w8SvSGUOqjkoGNFAlIw6lToaxMW5ciymCWgVLns= From: trondmy@kernel.org To: Steve Dickson Cc: linux-nfs@vger.kernel.org Subject: [PATCH 7/7] mountd: Check the stat() return values in match_fsid() Date: Thu, 16 Apr 2020 18:12:52 -0400 Message-Id: <20200416221252.82102-8-trondmy@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200416221252.82102-7-trondmy@kernel.org> References: <20200416221252.82102-1-trondmy@kernel.org> <20200416221252.82102-2-trondmy@kernel.org> <20200416221252.82102-3-trondmy@kernel.org> <20200416221252.82102-4-trondmy@kernel.org> <20200416221252.82102-5-trondmy@kernel.org> <20200416221252.82102-6-trondmy@kernel.org> <20200416221252.82102-7-trondmy@kernel.org> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Propagate errors from the stat() calls in match_fsid() so that the caller can be more careful about how they are handled. Signed-off-by: Trond Myklebust --- utils/mountd/cache.c | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index 79d3ee085a90..6cba2883026f 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -659,55 +659,66 @@ static int parse_fsid(int fsidtype, int fsidlen, char *fsid, return 0; } -static bool match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path) +static int match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path) { struct stat stb; int type; char u[16]; if (nfsd_path_stat(path, &stb) != 0) - return false; + goto path_error; if (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode)) - return false; + goto nomatch; switch (parsed->fsidtype) { case FSID_DEV: case FSID_MAJOR_MINOR: case FSID_ENCODE_DEV: if (stb.st_ino != parsed->inode) - return false; + goto nomatch; if (parsed->major != major(stb.st_dev) || parsed->minor != minor(stb.st_dev)) - return false; - return true; + goto nomatch; + goto match; case FSID_NUM: if (((exp->m_export.e_flags & NFSEXP_FSID) == 0 || exp->m_export.e_fsid != parsed->fsidnum)) - return false; - return true; + goto nomatch; + goto match; case FSID_UUID4_INUM: case FSID_UUID16_INUM: if (stb.st_ino != parsed->inode) - return false; + goto nomatch; goto check_uuid; case FSID_UUID8: case FSID_UUID16: - if (!is_mountpoint(path)) - return false; + errno = 0; + if (!is_mountpoint(path)) { + if (!errno) + goto nomatch; + goto path_error; + } check_uuid: if (exp->m_export.e_uuid) { get_uuid(exp->m_export.e_uuid, parsed->uuidlen, u); if (memcmp(u, parsed->fhuuid, parsed->uuidlen) == 0) - return true; + goto match; } else for (type = 0; uuid_by_path(path, type, parsed->uuidlen, u); type++) if (memcmp(u, parsed->fhuuid, parsed->uuidlen) == 0) - return true; + goto match; } - return false; +nomatch: + return 0; +match: + return 1; +path_error: + if (path_lookup_error(errno)) + goto nomatch; + return -1; } static struct addrinfo *lookup_client_addr(char *dom) @@ -815,8 +826,12 @@ static void nfsd_fh(int f) exp->m_export.e_path)) dev_missing ++; - if (!match_fsid(&parsed, exp, path)) + switch(match_fsid(&parsed, exp, path)) { + case 0: continue; + case -1: + goto out; + } if (is_ipaddr_client(dom) && !ipaddr_client_matches(exp, ai)) continue;