Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp601250ybg; Fri, 12 Jun 2020 09:36:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa527iCkAsovBnAUsQ8lSgrZETKdT61EZf1Lt7Y+zxaLbNHYjY3EUD5A5PoBefyDrXInrS X-Received: by 2002:a17:906:fb19:: with SMTP id lz25mr14527599ejb.349.1591979787552; Fri, 12 Jun 2020 09:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591979787; cv=none; d=google.com; s=arc-20160816; b=lewN7J8ouuDAzBvIoI6vqzZVa5mxX1omxvIUIjAlN9lF/6FbL9+d706jsHfHgXgmWq QHnlHJJGFMbVDgLq1aaV/83fo1fo9ZAU0dfGJ9j/GCdm1xyos7TXOhKZjUKZAmk9sLPS kOZiN04dC+oyMnO063vfzxRfT6/p2XqukA8rPM7rFNlGkpIMUxUDM0cRI3I9A5YI1kTv SOJwJHM6pC9JHkGDFpxdFUrnv7MIhx/+VH3Ln+1f4N7mOVKOUa4qy8ItTpiPAyhvUpz8 rRk4f3maEntqobNh1XCLT6zfMCjtg0Uwnx5rehM8inc8OeSBXhgdubO8yropMOxx9EbR Tlsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=m/JSRr/nFiYtLRndyGO1Ndt2WQLnMAvoHzIfrNhUs68=; b=QAmNzoe4Sm/Ti7qcmar79XYW0IRpRX88luaxbExOmkx4lsR7/Fpw7MTmDzecpFO6Aa 8zqCOkNA5iQDaDeqAavIk2Xofs/0D9GcjOMjjKibBcXKcMKH/cJ6ENin5tmHsQHllFa7 576QIvvpknmBUae6pEokhZ5QORHo35BLJDVVEsmW1xUIbFlFhW5b8jYOuDTsBFrqsMQE u59kS2vBxnJ7KfnQFwkrrR5dFLc+a42t0PHHyOW38ZvHOloSn0S+Fmuog5UeHP4tj3hO KyN0CdAeB7bNQHjYo6wh8q6H69ITW/uerRS0Z86tU2w0LJClJyk/jTGnfInGjIYkW8O1 1v5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=EIqDGtX3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf5si4114985ejb.186.2020.06.12.09.36.04; Fri, 12 Jun 2020 09:36:27 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=EIqDGtX3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726306AbgFLQeD (ORCPT + 99 others); Fri, 12 Jun 2020 12:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgFLQeD (ORCPT ); Fri, 12 Jun 2020 12:34:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2960CC03E96F for ; Fri, 12 Jun 2020 09:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=m/JSRr/nFiYtLRndyGO1Ndt2WQLnMAvoHzIfrNhUs68=; b=EIqDGtX3r7UiOAPU2+dmyLHeLL tt4cXsmHA2uQtpRQtXDAacphKQbJXKd87UdLGda4VdD4sbwE8ZJMGP+NkGft4XXymxLBPWe5Hx79c JYEsNknqmsXLDCK0crfjHCDNA2Vm3LLulS7pIQ7nto4lZu2lwZj9UGFVRIGU3MD94CSevI1MBY3uR fdTl8bG3yi9AaiSN9iQZjB7rB4ViC1M+7rYjp+04Y41g4ieIS/twQ4ig/N8pq+PqZL+POTzlrQ9hn 3f8WR2AOy0Sef8SuXUkO/+Zuaf0E9WCUWw6x1GGBo5lidcirrlhmkYCfP3YpDujlylZATfCFgMMNK Khmb/2gQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jjmcl-0003Pk-Rn; Fri, 12 Jun 2020 16:33:48 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8DF0E3003E4; Fri, 12 Jun 2020 18:33:45 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 698EE213CEB1E; Fri, 12 Jun 2020 18:33:45 +0200 (CEST) Date: Fri, 12 Jun 2020 18:33:45 +0200 From: Peter Zijlstra To: Xiaoming Ni Cc: paul@paul-moore.com, edumazet@google.com, paulmck@kernel.org, dhowells@redhat.com, keescook@chromium.org, shakeelb@google.com, jamorris@linux.microsoft.com, alex.huangjianhui@huawei.com, dylix.dailei@huawei.com, chenzefeng2@huawei.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] cred: Add WARN to detect wrong use of get/put_cred Message-ID: <20200612163345.GF2497@hirez.programming.kicks-ass.net> References: <1591957695-118312-1-git-send-email-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591957695-118312-1-git-send-email-nixiaoming@huawei.com> 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 06:28:15PM +0800, 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. Why not not use refcount_t? It has all that goodness and more.