From patchwork Mon Feb 1 05:00:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 12058035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FB47C433DB for ; Mon, 1 Feb 2021 05:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DED4664D9F for ; Mon, 1 Feb 2021 05:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbhBAFBQ (ORCPT ); Mon, 1 Feb 2021 00:01:16 -0500 Received: from mx2.suse.de ([195.135.220.15]:50680 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbhBAFBO (ORCPT ); Mon, 1 Feb 2021 00:01:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4CADEAC45; Mon, 1 Feb 2021 05:00:32 +0000 (UTC) From: NeilBrown To: Steve Dickson , Linux NFS Mailing list Date: Mon, 01 Feb 2021 16:00:27 +1100 Subject: [PATCH nfs-utils v2] mount: fix parsing of default options In-Reply-To: <87lfccfx5t.fsf@notabene.neil.brown.name> References: <20210106184028.150925-1-steved@redhat.com> <87o8h8fx7a.fsf@notabene.neil.brown.name> <87lfccfx5t.fsf@notabene.neil.brown.name> Message-ID: <875z3cfklw.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org A recent patch to change configfile.c to use parse_opt.c contained code which was intended to remove all "default*" options from the list before that could be passed to the kernel. This code didn't work, so default* options WERE passed to the kernel, and the kernel complained and failed the mount attempt. A more recent patch attempted to fix this by not including the "default*" options in the option list at all. This resulting in global-default defaults over-riding per-mount or per-server defaults. This patch reverse the "more recent" patch, and fixes the original patch by providing correct code to remove all "default*" options before the kernel can see them. Fixes: 88c22f924f1b ("mount: convert configfile.c to use parse_opt.c") Fixes: 8142542bda28 ("mount: parse default values correctly") Signed-off-by: NeilBrown --- I realized that po_remove_all() could free 'ptr' and then compare it against the next option, which would have undefined results. So best to strdup and free it. utils/mount/configfile.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c index e865998dd5a9..3d3684efa186 100644 --- a/utils/mount/configfile.c +++ b/utils/mount/configfile.c @@ -277,10 +277,9 @@ conf_parse_mntopts(char *section, char *arg, struct mount_options *options) } if (buf[0] == '\0') continue; - if (default_value(buf)) - continue; po_append(options, buf); + default_value(buf); } conf_free_list(list); } @@ -335,7 +334,11 @@ char *conf_get_mntopts(char *spec, char *mount_point, * Strip out defaults, which have already been handled, * then join the rest and return. */ - po_remove_all(options, "default"); + while (po_contains_prefix(options, "default", &ptr, 0) == PO_FOUND) { + ptr = strdup(ptr); + po_remove_all(options, ptr); + free(ptr); + } po_join(options, &mount_opts); po_destroy(options);