From patchwork Tue Jun 4 17:57:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10975887 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 615E613AD for ; Tue, 4 Jun 2019 17:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 522DC262AE for ; Tue, 4 Jun 2019 17:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4666828644; Tue, 4 Jun 2019 17:59:46 +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 F2145262AE for ; Tue, 4 Jun 2019 17:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbfFDR7p (ORCPT ); Tue, 4 Jun 2019 13:59:45 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:46743 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfFDR7p (ORCPT ); Tue, 4 Jun 2019 13:59:45 -0400 Received: by mail-io1-f68.google.com with SMTP id i10so8155002iol.13 for ; Tue, 04 Jun 2019 10:59:44 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=GT8X+EsNYBb5UMZWBMZ2Z4O0Ne33KByhJ3ztwwgYRAs=; b=ifE03cODeqTZxkm/JiWk/+7Tc9DwiSxTwJHOtBdil+wuwuYxxkbz9wrlXP2QOyJOwD PebTqbIn8H86AYvU/mpKML0FKOAX1nYKy7x1sSfxJ2VviKwevaCsxhQ3F/xXoSHMiQ0p YBhhZAi89CKNJEabz1Xhgc9cf1PpDDP41OjWLpLuyXlFE9xIkWy0Po+QAiN6CHzPzBRd BXOec8yBrOgTd37Msurp5RFE/dr42armY86Cy+j1YpPnN8MB+e/YFyZ9n2rLefPcybWQ 817H4SufcO90cH/0WpothfeixiI7zLwEAwfUrDDVSkM9lvI99s2gFD6iNYvZI3eutQBg HpwQ== 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=GT8X+EsNYBb5UMZWBMZ2Z4O0Ne33KByhJ3ztwwgYRAs=; b=Vo9NvNWEz8O2RL1QLKK7d2qQLOl4KwN18m7Mb55HruT2jSZYr8S6trBbuSZIwOElas +6l5aTc+0oXoCsqGN3bPkgEbm4Ck38rvf5px3+GImPybuNcARff+X1mjxI6XVenTcP/B +WRsU6mytbo07+APXMn8yQqf73KOd/HmYwJGSK7vvFiBw2Sg9cIVNBepfNI8xNvQpoN0 EqTBEUpkMBgGUllLQtHTUvZNNCn5iBcEMbDPbrQy16Pb5MosZV0uGTWYGQ6PgfBOApaf hpRGHaOyX44qTMewoZPdk7POlQEOcmCTjSwkGXw2paGxlbtjFFDKr498spS/SAFA58SB +5Uw== X-Gm-Message-State: APjAAAUGFoFAZzLZqFVLI6RKXAl55sblyx2T6CI3+sedpUn8CgeosdwS 8Vjcy79m4txdsvIHCHM+6w== X-Google-Smtp-Source: APXvYqz7dZShp1ZPjVCVYbHAatC6l0pUi4Lw17Rn0ic5YNQZ9H7xMAnzITYB/+3Y7ERABS76P3/g7w== X-Received: by 2002:a6b:c411:: with SMTP id y17mr425998ioa.265.1559671184176; Tue, 04 Jun 2019 10:59:44 -0700 (PDT) Received: from localhost.localdomain (50-36-175-138.alma.mi.frontiernet.net. [50.36.175.138]) by smtp.gmail.com with ESMTPSA id u134sm8355134itb.32.2019.06.04.10.59.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 10:59:43 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Steve Dickson Cc: "J. Bruce Fields" , linux-nfs@vger.kernel.org Subject: [PATCH v2 1/3] mountd: Fix up incorrect comparison in next_mnt() Date: Tue, 4 Jun 2019 13:57:32 -0400 Message-Id: <20190604175734.98657-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604175734.98657-1-trond.myklebust@hammerspace.com> References: <20190604175734.98657-1-trond.myklebust@hammerspace.com> 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 We want to ensure that we compare the full name of the last component. Reported-by: "J. Bruce Fields" Signed-off-by: Trond Myklebust --- utils/mountd/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index d818c971bded..d616d526667e 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -400,7 +400,7 @@ static char *next_mnt(void **v, char *p) while ((me = getmntent(f)) != NULL && l > 1) { mnt_dir = nfsd_path_strip_root(me->mnt_dir); - if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] != '/') + if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] == '/') return mnt_dir; } endmntent(f); From patchwork Tue Jun 4 17:57:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10975889 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 D707113AD for ; Tue, 4 Jun 2019 17:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C707A262AE for ; Tue, 4 Jun 2019 17:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB68E28644; Tue, 4 Jun 2019 17:59:47 +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 62610262AE for ; Tue, 4 Jun 2019 17:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726286AbfFDR7q (ORCPT ); Tue, 4 Jun 2019 13:59:46 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:33967 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfFDR7q (ORCPT ); Tue, 4 Jun 2019 13:59:46 -0400 Received: by mail-io1-f68.google.com with SMTP id k8so18103038iot.1 for ; Tue, 04 Jun 2019 10:59:46 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=nuScPeIemDw/G/sUVtG0oFFkp5S32VkMHRBfBR4eWwQ=; b=iRFIuiVJ0scLS2gACm+2X3EUXYKGNWUxw6jtEOYwEaB8FBjnigZ47P825UOfki4+1e LvSlAHJM2pnSf1XJKj7g7AyytdBjoArBS7x9AjEuOsQgqTlQJWwQGozuQy0iCFG7CKPR U2MENpJBVjtL7VdL2P+iOGpXfa54NO44o41v+hOgcwNjCAK8Tb0mxvCZNVoAwZYh/g3N 9nOqfcQEDrBm3TRtAq3nGmPn1b57ZcwDs/Vnw+79Xie9hf693LGfCgUpFF2ci7iPxCMm mSpoF1LDWLsD5n2b5Xz8W8fbECQ2XHgwEPFIpWbOEVoavOwwFbvQx0HBfsNAJCDWwlsk cVSg== 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=nuScPeIemDw/G/sUVtG0oFFkp5S32VkMHRBfBR4eWwQ=; b=qrmjqQ6UAvJHzFAe6thaXw7G31HGM2dTGXPpdQp6OSH2v3XeahdtmdJ45PBMjlHTDv kWVEYnJZ0LwOzl1YWDLL2JSivT2O2memfaE8wFMbM92A1518jcar+8xGvn9oC6FRA45U NMAqzjyMjn188iUsz5SITjsn/tHCUc39aVOR3SvKyrksS8n+zvNdGLpo3svbyM5o4lWr GtHo+9dqVgRp4Zz0G+TQaulf8F2nvdM3P7rGJRDgX7HINdwgA4DZZhUbCuqB4bBle4wy EQuppwcsYVHk5D2rDNWMXdONAHIA85vLbA0JiPW1Ika7glq7zaDm0QCnaepHAuK0TM1R hiVw== X-Gm-Message-State: APjAAAX5xD1EGC0VePkYHtwU83FnvJKyA21XJM8RS2tYnCmfNw65ddGE vtykdqAMnLPUtY5gx3aXpA== X-Google-Smtp-Source: APXvYqzoIMCjEjVxXQTOT9UQ07PPLSFNmeUKMYQFe4hlZsb5ZPW0OC0LPaBjgRB0+npLBxKQE9reJQ== X-Received: by 2002:a6b:7017:: with SMTP id l23mr19231765ioc.159.1559671185340; Tue, 04 Jun 2019 10:59:45 -0700 (PDT) Received: from localhost.localdomain (50-36-175-138.alma.mi.frontiernet.net. [50.36.175.138]) by smtp.gmail.com with ESMTPSA id u134sm8355134itb.32.2019.06.04.10.59.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 10:59:44 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Steve Dickson Cc: "J. Bruce Fields" , linux-nfs@vger.kernel.org Subject: [PATCH v2 2/3] mountd: Ensure nfsd_path_strip_root() uses the canonicalised path Date: Tue, 4 Jun 2019 13:57:33 -0400 Message-Id: <20190604175734.98657-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604175734.98657-2-trond.myklebust@hammerspace.com> References: <20190604175734.98657-1-trond.myklebust@hammerspace.com> <20190604175734.98657-2-trond.myklebust@hammerspace.com> 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 When attempting to strip the root path, we should first canonicalise the root pathname. Signed-off-by: Trond Myklebust --- support/misc/nfsd_path.c | 17 ++++++++++++----- utils/mountd/cache.c | 6 ++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/support/misc/nfsd_path.c b/support/misc/nfsd_path.c index 2f41a793c534..84e48028071c 100644 --- a/support/misc/nfsd_path.c +++ b/support/misc/nfsd_path.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -62,13 +63,19 @@ nfsd_path_nfsd_rootdir(void) char * nfsd_path_strip_root(char *pathname) { + char buffer[PATH_MAX]; const char *dir = nfsd_path_nfsd_rootdir(); - char *ret; - ret = strstr(pathname, dir); - if (!ret || ret != pathname) - return pathname; - return pathname + strlen(dir); + if (!dir) + goto out; + + if (realpath(dir, buffer)) + return strstr(pathname, buffer) == pathname ? + pathname + strlen(buffer) : NULL; + + xlog(D_GENERAL, "%s: failed to resolve path %s: %m", __func__, dir); +out: + return pathname; } char * diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index d616d526667e..ecda18c75a0f 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -390,7 +390,6 @@ static char *next_mnt(void **v, char *p) FILE *f; struct mntent *me; size_t l = strlen(p); - char *mnt_dir = NULL; if (*v == NULL) { f = setmntent("/etc/mtab", "r"); @@ -398,7 +397,10 @@ static char *next_mnt(void **v, char *p) } else f = *v; while ((me = getmntent(f)) != NULL && l > 1) { - mnt_dir = nfsd_path_strip_root(me->mnt_dir); + char *mnt_dir = nfsd_path_strip_root(me->mnt_dir); + + if (!mnt_dir) + continue; if (strncmp(mnt_dir, p, l) == 0 && mnt_dir[l] == '/') return mnt_dir; From patchwork Tue Jun 4 17:57:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10975891 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 104E314C0 for ; Tue, 4 Jun 2019 17:59:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 008EC262AE for ; Tue, 4 Jun 2019 17:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E88B528644; Tue, 4 Jun 2019 17:59:48 +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 9887F262AE for ; Tue, 4 Jun 2019 17:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbfFDR7s (ORCPT ); Tue, 4 Jun 2019 13:59:48 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:33884 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfFDR7r (ORCPT ); Tue, 4 Jun 2019 13:59:47 -0400 Received: by mail-it1-f194.google.com with SMTP id u124so3149495itc.1 for ; Tue, 04 Jun 2019 10:59:47 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=j1UkUfTZsFI//kdDQAkgjA8sveaR01sXEVy3hYpGpgU=; b=Xu4NxJaHDjm65MH4JTo/NY0/1t8cCRg+hy7oxY7LM6Ck4UO+By9GHRy3pggsM5v85b rZH7125ctjq3V8gIPD6WP+aT478pMPPSpdFw/26Ah3TC2UvswOAzDq0uFroeWdfI9PLF 2Q8wFrZdAcYyAVTLRRXBKlgrCxtB8/zLZhNlXMPouH7lY286GObFOdX3BclxQNl5k/ZH +z9N/dTR5sSpE0D1qZx0h84EvKrX69VxoWJy4fuVteZG5brYbnXKT4vCCaiw9CWjy4XJ f3cicqyI8Ku/CZuV4j31IBkLF3DVLVVdTTlStzz6ROWETbZCQuknLN6PLP4DKh+ie8D+ Z6NA== 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=j1UkUfTZsFI//kdDQAkgjA8sveaR01sXEVy3hYpGpgU=; b=HbbJPYhxTiBgJ2MQfM7kE9HNHH6JWkOTq+Glj45zGpXV04wE+fp2G8vHlYEvO3lhru Xt7TgkOcYqzuvIloi9gzAlN5O9LKEhN5dZC/0UpHCfWBHG42NN3vGa5q+f/+WD2mSW9U xLoYmOv4YF94h9zoQlkVAZaxwqmvBVwrTDibBwoY1PhSBTeZ8hvWlo9HIGVvJeABaqSu 85JsVqpvXV0NPMxiqmGp2ffAxYGY7/HjGl5VUihw7ODuD7RByhSfLFL9ETKgtjL05gQ7 hMgoD3BMzRDaYTjoqdG+07YJLF8u4vehuXRRZgL4AY4gWEevtt2QpW+edyOqwiep0gDb nGjQ== X-Gm-Message-State: APjAAAVnCGI/cfHYTmKJjxWj8B4GELf3MYuKFkaQl9nFzQ93ULVIf4Rx 4W7T6YDwSpuofqTh5ETi7NjLJr0= X-Google-Smtp-Source: APXvYqxTtSRHJShgK6pBgjXNodxETMrwf+rto4FTPl7F553KXVheZD1cQOHUCEg4Ux3o4DcNcakbEA== X-Received: by 2002:a02:7b2d:: with SMTP id q45mr18317268jac.127.1559671186597; Tue, 04 Jun 2019 10:59:46 -0700 (PDT) Received: from localhost.localdomain (50-36-175-138.alma.mi.frontiernet.net. [50.36.175.138]) by smtp.gmail.com with ESMTPSA id u134sm8355134itb.32.2019.06.04.10.59.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2019 10:59:45 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Steve Dickson Cc: "J. Bruce Fields" , linux-nfs@vger.kernel.org Subject: [PATCH v2 3/3] mountd: Canonicalise the rootdir in exportent_mkrealpath() Date: Tue, 4 Jun 2019 13:57:34 -0400 Message-Id: <20190604175734.98657-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190604175734.98657-3-trond.myklebust@hammerspace.com> References: <20190604175734.98657-1-trond.myklebust@hammerspace.com> <20190604175734.98657-2-trond.myklebust@hammerspace.com> <20190604175734.98657-3-trond.myklebust@hammerspace.com> 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 Ensure that we canonicalise the export path when generating the real path. Signed-off-by: Trond Myklebust --- support/export/export.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/support/export/export.c b/support/export/export.c index 82bbb54c5e9e..c753f68e4d63 100644 --- a/support/export/export.c +++ b/support/export/export.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include "nfslib.h" #include "exportfs.h" #include "nfsd_path.h" +#include "xlog.h" exp_hash_table exportlist[MCL_MAXTYPES] = {{NULL, {{NULL,NULL}, }}, }; static int export_hash(char *); @@ -38,8 +40,14 @@ exportent_mkrealpath(struct exportent *eep) const char *chroot = nfsd_path_nfsd_rootdir(); char *ret = NULL; - if (chroot) - ret = nfsd_path_prepend_dir(chroot, eep->e_path); + if (chroot) { + char buffer[PATH_MAX]; + if (realpath(chroot, buffer)) + ret = nfsd_path_prepend_dir(buffer, eep->e_path); + else + xlog(D_GENERAL, "%s: failed to resolve path %s: %m", + __func__, chroot); + } if (!ret) ret = xstrdup(eep->e_path); eep->e_realpath = ret;