Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1699047pxb; Wed, 9 Feb 2022 02:31:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdFFRktUFCG+AN+i+uWeOwCXU6fIUs4lucNOJNX/mepHRzfrdva9EyYaADwtWyYjWDTisI X-Received: by 2002:a17:902:c24d:: with SMTP id 13mr1482098plg.22.1644402693137; Wed, 09 Feb 2022 02:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644402693; cv=none; d=google.com; s=arc-20160816; b=IPk6g+s9gH8vrhdJ3GNzbcAopqysp2/qtVJqGOtYZ9f10kGYiOF9FkZa8JoYyvxz49 FGlWRWVx/xXDdVpo/T71X0P0dP/kaVHnbKO+4oyO5OShN2Qe+An0meLTp7To9AyzusmY 8eb17t95O4m7apUWGQ2mQbHBs3fXkCQArPBl7MmB/f49l3QDmoK5Tsjr0BAgcFS2vXGB /Qyy6EG0nQlNqM6h6k11Fyph11Xleg/DttJx5tU92n6GZu6HxzCJqF0p6w1PyTjNQHDr 6QXl8O84xsgLHrJW8jb7dGMWnEsacF3bqyRiIC8VJf5XIRNiVBT6tXLOecUhKvydPFVr 6QYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qUdvaTQsHJmLMCJWSlA1Dxlki0I2TIrcg8aJ3ZGHXCE=; b=aUjR8+smEnObNtlqoQRFER/QfksD3swfbSzrFLwuooncCkOlZ4jBK3tZB9G4zKKRcv AmIle1lAaYli1NyzXOGgjILrSMaa1PmtZrawOQQiqgclKeMUjePnoXqlnbyQbwHCEXjl 0aQZxrcJYCOoC6CXIslivNVvK6JP3jTonbOBMFSRav33gCaBR4MoXuRl3+OU3ZCZspYT 3+X00YcmZ3NKt9t+rYKiKrmrwk/MprOoymCE7wjlnWWh8MOINdOKyP/gv/2A06VB71L0 E8xYwk+knQbdN6949mP7hWJPgJon4KO+T+kF+Fo7J3hNzpPx62g6tWl9UA3GCSTkAbT3 TILQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hIZGJrzt; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b15si14784137pfm.25.2022.02.09.02.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:31:33 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hIZGJrzt; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2024E00E583; Wed, 9 Feb 2022 01:21:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387246AbiBHWXH (ORCPT + 99 others); Tue, 8 Feb 2022 17:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386969AbiBHVhv (ORCPT ); Tue, 8 Feb 2022 16:37:51 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2DF20C0612B8 for ; Tue, 8 Feb 2022 13:37:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644356269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qUdvaTQsHJmLMCJWSlA1Dxlki0I2TIrcg8aJ3ZGHXCE=; b=hIZGJrztlpgyThvQ3fxhkfyri7AUx5RNAL/gZ2w4KcRWzgAIAvYi11Szq1g3AkCCkUyXkh O5qTX4oPeD1Ks+pg7XIbwqrZZdBxudoqe5zqYOc6hIPU7ReAwkvcF9kbAJhXEDtJBjqkfM eG9YQdtOQ/W7AfjBdL7hl4pL9H/H648= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-425-_-Qed2gcMGCi0BIqXlgFEg-1; Tue, 08 Feb 2022 16:37:47 -0500 X-MC-Unique: _-Qed2gcMGCi0BIqXlgFEg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F969100C660; Tue, 8 Feb 2022 21:37:46 +0000 (UTC) Received: from [172.16.176.1] (ovpn-64-2.rdu2.redhat.com [10.10.64.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA6514CEE8; Tue, 8 Feb 2022 21:37:45 +0000 (UTC) From: "Benjamin Coddington" To: "Trond Myklebust" Cc: anna.schumaker@netapp.com, linux-nfs@vger.kernel.org Subject: Re: [PATCH] NFSv4: use unique client identifiers in network namespaces Date: Tue, 08 Feb 2022 16:37:44 -0500 Message-ID: <7CDAEA98-3A8D-459A-80FE-82AA58A4EDA2@redhat.com> In-Reply-To: <189aba691b341f64f653817c9cdf018ef34ac257.camel@hammerspace.com> References: <6e05bf321ff50785360e6c339d111db368e7dfda.1644349990.git.bcodding@redhat.com> <189aba691b341f64f653817c9cdf018ef34ac257.camel@hammerspace.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On 8 Feb 2022, at 15:27, Trond Myklebust wrote: > On Tue, 2022-02-08 at 15:03 -0500, Benjamin Coddington wrote: >> In order to differentiate client state, assign a random uuid to the >> uniquifing portion of the client identifier when a network namespace >> is >> created.  Containers may still override this value if they wish to >> maintain >> stable client identifiers by writing to >> /sys/fs/nfs/net/client/identifier, >> either by udev rules or other means. >> >> Signed-off-by: Benjamin Coddington >> --- >>  fs/nfs/sysfs.c | 14 ++++++++++++++ >>  1 file changed, 14 insertions(+) >> >> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c >> index 8cb70755e3c9..9b811323fd7f 100644 >> --- a/fs/nfs/sysfs.c >> +++ b/fs/nfs/sysfs.c >> @@ -167,6 +167,18 @@ static struct nfs_netns_client >> *nfs_netns_client_alloc(struct kobject *parent, >>         return NULL; >>  } >>   >> +static void assign_unique_clientid(struct nfs_netns_client *clp) >> +{ >> +       unsigned char client_uuid[16]; >> +       char *uuid_str = kmalloc(UUID_STRING_LEN + 1, >> GFP_KERNEL); >> + >> +       if (uuid_str) { >> +               generate_random_uuid(client_uuid); >> +               sprintf(uuid_str, "%pU", client_uuid); >> +               rcu_assign_pointer(clp->identifier, >> uuid_str); >> +       } >> +} >> + >>  void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) >>  { >>         struct nfs_netns_client *clp; >> @@ -174,6 +186,8 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns, >> struct net *net) >>         clp = nfs_netns_client_alloc(nfs_client_kobj, net); >>         if (clp) { >>                 netns->nfs_client = clp; >> +               if (net != &init_net) >> +                       assign_unique_clientid(clp); > > Why shouldn't this go in nfs_netns_client_alloc? At this point you've > already published the pointer in netns, so you're prone to races. No reason it shouldn't, I'll put it there if that's what you want. I thought that's why it was RCU-ed, and figured we'd just do it before the uevent. > Also, why the exclusion of init_net? Because we're unique enough if we're not in a network namespace, and any additional uniqueness we might need (due to NAT, or cloned VMs) /should/ be getting from udev, as you envisioned. That way, if we are getting uniquified, its from a source that's likely persistent/deterministic. If we just generate a random uniquifier, its going to be different next boot if there's no udev rule and userspace helpers. That's going to make things a lot worse for simple setups. Ben