From owner-freebsd-hackers@freebsd.org Sat Sep 5 03:57:59 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3C4903DD07F for ; Sat, 5 Sep 2020 03:57:59 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bk13V1SNxz3Z0B for ; Sat, 5 Sep 2020 03:57:57 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-ot1-f52.google.com with SMTP id m12so4753273otr.0 for ; Fri, 04 Sep 2020 20:57:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XyrSBdJcPOabA+ZRMIjQMKg/LmXQXyxBzGHktzeK1RE=; b=o4axgvin/rnY2cTKTdkJ13t4pRxt8/20LWHJr3W6e2XK2x5cSoo8Fi/oVXHyujO41F sWNeiO81KhZ/l2j9XEN7/ZWVKpyWpGPytEcK5fE9NNFbgczCvwirOloA9KiZj95SkKEc mackBkIy7G/+MK1ZwsSX52N5BYdDwEVS+PBighcBrqJeUUaPOJgb4zFVMfZJEAz73+Vj wafY3OQUF2i0bXrJ9+5LxirG4jULWEz8rEFCXsJ7jU350zvayk2LettFAfFcWTlQCDSP 69mi8W9qQ6YVJ8Jo0b/2ByCsIxbb4nAjzFmGRCrK69iKfzJyi5FV9X2O0dY/vUCbvMu5 dSNw== X-Gm-Message-State: AOAM533LHbTsS/75X98tJ5kLk2Mf+OGuT1YitVKvNdj16v5ef9+uW0tz +Yf2BLM5Seza7tVzpDlYl7lmSMaC4qjTkmC3PrrIayZ5l/g= X-Google-Smtp-Source: ABdhPJxXvsNmVYbGITrvsKVrKGGW4GACgjQ0wJ5a93m/kP5fD7BDnymK9TjHI2Bpx6C7UatSLiMo4U6uXSv6khLexNg= X-Received: by 2002:a9d:758b:: with SMTP id s11mr7326536otk.251.1599278276562; Fri, 04 Sep 2020 20:57:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alan Somers Date: Fri, 4 Sep 2020 21:57:45 -0600 Message-ID: Subject: Re: panic!("docallb") in nfsrv_docallback To: Rick Macklem Cc: FreeBSD Hackers X-Rspamd-Queue-Id: 4Bk13V1SNxz3Z0B X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.210.52 as permitted sender) smtp.mailfrom=asomers@gmail.com X-Spamd-Result: default: False [-3.39 / 15.00]; RCVD_TLS_ALL(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FREEFALL_USER(0.00)[asomers]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[209.85.210.52:from]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; NEURAL_HAM_LONG(-1.02)[-1.024]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; ARC_NA(0.00)[]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; SUBJECT_HAS_EXCLAIM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[209.85.210.52:from]; NEURAL_HAM_SHORT(-1.29)[-1.291]; NEURAL_HAM_MEDIUM(-1.08)[-1.077]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; MAILMAN_DEST(0.00)[freebsd-hackers] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Sep 2020 03:57:59 -0000 On Fri, Sep 4, 2020 at 8:58 PM Rick Macklem wrote: > Alan Somers wrote: > >I just saw this panic on a 12-stable machine. Unfortunately, I don't have > >a core dump, just a stack trace. It was serving NFS v4.0, with > delegations > >enabled. The clients were all Debian, with Linux 3.16.0. > I will generically note that I believe the Linux NFS client developers > mostly > test NFSv4.1, 4.2, so if the clients support NFSv4.1, it might be worth > upgrading? > > Also, delegations aren't enabled by default for a couple of reasons. > 1 - For a long time, Linux only knew how to use read delegations and I felt > (and still feel) they are pretty useless. > 2 - They are complex to get right. > 3 - Although they should reduce the number of Open operations against the > server, I haven't observed dramatic performance improvements because > of them. > > >The proximal cause of the panic seems to be that the file had a write > >delegation issued to an unconfirmed client. Root cause is harder to > >determine. Did the kernel previously issue a delegation to an unconfirmed > >client? Or did the client somehow change to an unconfirmed state after > the > >delegation was issued, perhaps due to a race? > I think the first case is more likely. Since client confirmation happens > immediately > for NFSv4.1 (the ExchangeID and Createsession must occur before anything > else can happen), I wouldn;t be surprised if the Linux client tries to do > an Open > before the SetClientIDConfirm has completed for NFSv4.0. > > >It's hard to tell, but I don't see any checks for lc_flags & > >LCL_NEEDSCONFIRM in nfsrv_openctrl (which issues the delegations), so I'm > >guessing that that's the problem. > The server should definitely check for a confirmed ClientID during Open and > fail any Open attempt where that is not the case. > --> I'll take a look at the code. I wrote it about 20years ago, but I can > probably > figure out how it works.;-) > > > If so, then the event trace would look > >like this: > > > >1) Client Alice sends SETCLIENTID. The server creates a client state > >structure > > for her. > >_) Client Alice should've sent SETCLIENTID_CONFIRM, but doesn't. Bad > Alice! > >2) Client Alice sends OPEN for some file, and is issued a write > delegation. > > The server shouldn't have issued it, because Alice's client ID is > > unconfirmed. Bad server! > >3) Client Bob tries to do a GETATTR on that same file. > >4) In nfsrv_checkgetattr, the kernel finds a write delegation for that > file, > > owned by client Alice. > >5) The kernel tries to send a NFSV4OP_CBGETATTR callback to Alice, to see > >if the > > file's attributes have changed. > >6) But Alice's client ID is unconfirmed. Oh no! Panic! > > > >Does this sound plausible? Should there be a check for LCL_NEEDSCONFIRM > >somewhere around line 3166 in nfs_nfsdstate.c? Grateful for any help. > Yes, it does. I would have thought that I'd have checked for the > unconfirmed > ClientID, but maybe not. > > It is also possible that the client somehow did a SetClientID after the > Open > that issued the delegation, putting it back in "unconfirmed" state. > It that was the case, maybe the panic(), intended to catch corrupted data > structures, was overkill. > > >-Alan > > > >P.S.: stack trace > > > >kdb_backtrace > >vpanic > >panic > >nfsrv_docallback > >nfsrv_checkgetattr > nfsrv_checkgetattr() should probably check for the case of an unconfirmed > clientid and then return ignoring any delegations hanging off it instead > of attempting a callback. > --> This would handle the case where the client did a SetClientID after the > Open that acquired the delegation, leaving the ClientID unconfirmed. > - The two RPCs doing SetClientID and SetClientIDConfirm are normally > done only upon mounting or when the client thinks it has lost the > ClientID due to a lease expiry, but there is also the case where > it is > changing the callback address. (This could explain the SetClientID > happening after the Open that acquired the delegation.) > --> Hint. Can you now see why NFSv4.1 chose to do things differently? > > nfsrvd_getattr > nfsrvd_dorpc > nfssvc_program > svc_run_internal > svc_thread_start > fork_exit > fork_trampoline > > Thanks for reporting it. I'll take a look, rick > Wow, thanks! That's better feedback than I ever hoped for. About fixing the bug: my odds of reproducing it in the original setting are low, since it's a production server. And I doubt I could force it via normal traffic to a development server, either. It took many terabytes of traffic to hit the bug this once. I think my best shot would be to use LibNFS ( https://github.com/sahlberg/libnfs) to write a custom misbehaving NFS client. But that's daunting; the only NFSv4 examples are nearly 1,000 lines each. But, I could probably do it with enough time. Do you have any better ideas? -Alan