Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp602171ybg; Fri, 12 Jun 2020 09:38:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOSbIyRzUSeEkM0qrXYuSaxfhrJDZD68Zsds2rRPSTrFP6jRnGUaBus0fzkh/sRz4IecD4 X-Received: by 2002:a17:906:2a4d:: with SMTP id k13mr14619819eje.253.1591979882375; Fri, 12 Jun 2020 09:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591979882; cv=none; d=google.com; s=arc-20160816; b=nkFB3m4MSHVv3ZgwhzMxN+vtA097ELFMANeZvF0hsZvtSWce3SoIzDlIWE7Rh8mG1m 8Hru+dCJp4LwZHRY5o3YETJm/s1EmaUjXM5H//ArbqPwQY5CN+GI8M5B2IJBMMjZqtVz ND+3sEEmjMdjauEO/lFmm9rT9YOTnQIeeVdsZ0Ei4/AvtPLXkz9EeF2oEUU5FolBgKQL xrc28M5EruZr8U+kHg8uiqRNbYTgbEHDAkqEwYTkurJD8uwxrPoe8tGR57HkwR1Ft9qK epW77IItwLyBcprVSamDaZbtVieSNqDI2owr2EPB9s//YCmcer3oBbnAh/sfCJ9vIbod r3Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zabfBP1pg2tNim+1vjkeMscLKnVu7/KPrta1MhgcgyQ=; b=HvKyFkO/x4pD0H9f1FWHU9otAdJ28TrIhXFx5ZUSknIB1qdnInWJlkmXHb5vPXjNze Q10LxTbxyw2zAr2DyoTffEr+ccI0lRdVCE4ZnC5Lu1g+py+ey59c1rcPXqTgt5t4YZRV 8GLYgJ+X3e4Nf0DFnAIaMNSR7kto9m6loVBdM4lGjovahyCcxFpQnJmZNAU8U1/kfInw mXUHAyz8hyK0DvG2QkyLSXASoCV2UqLFobEGMiAqG1zXr1UIobi4Mx9vU3lvMADgs4/e tU9UrBEqw00yc3Zt2b4o32fClodcclT47O/DNUM24vqduLqmTFjOD9oII6ijWEbQlsuS EBNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Yf/VXXjj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ly20si4162680ejb.474.2020.06.12.09.37.39; Fri, 12 Jun 2020 09:38:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Yf/VXXjj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbgFLQcy (ORCPT + 99 others); Fri, 12 Jun 2020 12:32:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726219AbgFLQcx (ORCPT ); Fri, 12 Jun 2020 12:32:53 -0400 Received: from mail-yb1-xb44.google.com (mail-yb1-xb44.google.com [IPv6:2607:f8b0:4864:20::b44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD684C03E96F for ; Fri, 12 Jun 2020 09:32:51 -0700 (PDT) Received: by mail-yb1-xb44.google.com with SMTP id y13so5177363ybj.10 for ; Fri, 12 Jun 2020 09:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zabfBP1pg2tNim+1vjkeMscLKnVu7/KPrta1MhgcgyQ=; b=Yf/VXXjj3fSOZHK6EIDIz/1TXQFuDjGymK4LlVlHSjbdDApthlI7vKqb0ID/lGnDiO Wvx+5O0CDvc6ZesKfGw9SJ6Uk0pmvm86j6UGSlDJxxWQn1UuBnnuR2tm2JiCGfYW1gms UlfaRap7fmeWj+soLcwj3C9g+Gskcx8Xx1wtp9UPI+6oSR7VMBwAZRsxrYuTsLAFEZul q/gkdEk+3/Sv1E2MRuMHCXGUY8EkKEw5awbPafNBSw6we5MDGNgUIB49YZAxI38uJ2/o /jdIh9FUU0c2DfCtd5yTvGnpAhw8vZ9CXKqZ8xuBUTdLBA3GDj4Xs6/eFq+O0HH32Vt0 JC3A== 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=zabfBP1pg2tNim+1vjkeMscLKnVu7/KPrta1MhgcgyQ=; b=rgm5qwbAJQvJ+ouXdA/AQ+x3BSGJbj5jxOCkWnZJrQYqRokAqWoLRFPVUDT4fyVJhB 9LaZIrbeB0IP4/q0s6PPkJga2kO3YVTGbbSKzxaCKz/Zmbp9fSdjeeJzHjtRSPa7c59R gb6UAjliNo37ywB4aD4bZ80T4EH7MMFCgUFRTRKnl0Q31qu58VA4IqSMkuS33TND4/1Z PVd6E/bpGCNqbKovY7Xr6JXyAY7gbJ060bTwngwedoZDCLTy/+n8bGM5GF18XV61mmIU wx5A+gMzTNrMVMTu8CXcpkthIuDFNyKY1+yBdv6LYgggyCZhCQZuvTcbp2DEcO8DZ/Cv 5bOw== X-Gm-Message-State: AOAM530oApixskq0/CbA36ZNS9IajM+UOan3SYwdNHQ4yK4ALLEfFfDv 09S6MGIVfHWWIOMB3Mki+Rsobsi4PG+kTxLKBfL9Yw== X-Received: by 2002:a25:9bc6:: with SMTP id w6mr23911166ybo.408.1591979570381; Fri, 12 Jun 2020 09:32:50 -0700 (PDT) MIME-Version: 1.0 References: <1591957695-118312-1-git-send-email-nixiaoming@huawei.com> In-Reply-To: <1591957695-118312-1-git-send-email-nixiaoming@huawei.com> From: Eric Dumazet Date: Fri, 12 Jun 2020 09:32:39 -0700 Message-ID: Subject: Re: [PATCH RFC] cred: Add WARN to detect wrong use of get/put_cred To: Xiaoming Ni Cc: Paul Moore , Peter Zijlstra , "Paul E. McKenney" , David Howells , Kees Cook , Shakeel Butt , jamorris@linux.microsoft.com, alex.huangjianhui@huawei.com, dylix.dailei@huawei.com, chenzefeng2@huawei.com, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 12, 2020 at 3:28 AM Xiaoming Ni wrote: > > Cred release and usage check code flow: > 1. put_cred() > if (atomic_dec_and_test(&(cred)->usage)) > __put_cred(cred); > > 2. __put_cred() > BUG_ON(atomic_read(&cred->usage) != 0); > call_rcu(&cred->rcu, put_cred_rcu); > > 3. put_cred_rcu() > if (atomic_read(&cred->usage) != 0) > panic("CRED: put_cred_rcu() sees %p with usage %d\n", > cred, atomic_read(&cred->usage)); > kmem_cache_free(cred_jar, cred); > > If panic is triggered on put_cred_rcu(), there are two possibilities > 1. Call get_cred() after __put_cred(), usage > 0 > 2. Call put_cred() after __put_cred(), usage < 0 > Since put_cred_rcu is an asynchronous behavior, it is no longer the first > scene when panic, there is no information about the murderer in the panic > call stack... > > So, add WARN() in get_cred()/put_cred(), and pray to catch the murderer > at the first scene. > > Signed-off-by: Xiaoming Ni > --- It seems you reinvented refcount_t ?