Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp623516ybg; Fri, 12 Jun 2020 10:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMNN3QtsxeJLGGQRh6QXjHyzTuIoy1TKK2Y45PE144f9zNBFAGZTzt3jXdYr+fwHYMHxUk X-Received: by 2002:a17:906:84a:: with SMTP id f10mr14764369ejd.102.1591981742775; Fri, 12 Jun 2020 10:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591981742; cv=none; d=google.com; s=arc-20160816; b=Xoyvl2Fpm2oVotGzAMh30XkwQp9cRPfVP+HPcbmyBAy2gWFReY+xdO9LNRG47BudIs 4a6zL7krF2XPgs/CHKRVPuKF5n8wEf0JEZZcgGgJKij7wngmJiOEF0rqPEFcLP/V6BxW BXN1gnJTwi4IQG2eh7mJxdjOVmjm/bPr7HesDnx+09aHr0yExYsvPf1mCXBHBaYQU22R fLlgf6qGGgRhVtwTu2spQ30VxnUP5yhSybvxUurFD1X1XuRZXeWcb03xdIFfqr17po2g ZrLSWcbygmIX2Y8v18vXRxMYAAuSruHi7mwKoXi2Hv1BTu8cn7o9m7wAbQo2JndJmsVj PnPw== 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=bVTxDzO4IZAFd863UtOldIkTlBTqxYr5OyZkbNt9Exo=; b=NChKtVkow5QmjQHehbsaz2TvMByNGJyiev2BHQ7MGXGWGsItb2i1Q1NcfDIB4bIAFS j/RP4zQvF+uwVh7mmc3ox2b3f0DZ31p3ngA083ZpQIU7K/nEJvnkuJnvMfdFKElySH0Q 4cOdPMUZjG0W1O7Mn/DNSgrPgol27iWroiRjMtEzUwdcaYUcO/tpmRk0sgTNgbjaGOhN aog80v1vRJNWDhJqu2H+7dQXbZ/Xh2BcsBvLWv1DlUj6AJzea2l0LD38WKstvJgfraQI v7zq75aeYfOFetB6dzdJMRToGYEOb9+3W6MtMnYfkNqUvR3AYtew08BkOSkkyt7RL+GO FZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A8Kp91uL; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q6si3630561edr.270.2020.06.12.10.08.39; Fri, 12 Jun 2020 10:09: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=@chromium.org header.s=google header.b=A8Kp91uL; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbgFLRGw (ORCPT + 99 others); Fri, 12 Jun 2020 13:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726219AbgFLRGw (ORCPT ); Fri, 12 Jun 2020 13:06:52 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70E91C03E96F for ; Fri, 12 Jun 2020 10:06:52 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id d6so4106829pjs.3 for ; Fri, 12 Jun 2020 10:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bVTxDzO4IZAFd863UtOldIkTlBTqxYr5OyZkbNt9Exo=; b=A8Kp91uLI+tQnJ3jKC2jR+cD8mIyaVyhikfRs5WrP7Tf5fkSUzCnv3fpv+kDxW46D8 zByT6xorZdwpIhX3RK1H3dShiz7nBjBJHSaxYamI70PD3uOr04gMI8pZX3ZMRktzqAXk T7mXdzqrUXZaHCkLNVFfsi4oNSiSBYSb9n5eo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bVTxDzO4IZAFd863UtOldIkTlBTqxYr5OyZkbNt9Exo=; b=H0X0q9qkvqEASh8+SFuxoq5eNL4/nx4nG9vjcc+w+T3C4DISgBVVbCtqLjHwkP0dQM LYLfXGpBTNF5pfU5ctl9ctbYEP605WJw/YMPSROLf+yulVBTItUwG9TtFou9gx6Gktlx m1kMeAKhs6pDrTU0Lnsw7HT7PNnR9wVeREUZ7IqOX8MstTmMkResvN+qMwxPy8rAbsI+ HC+LGWBHcscL/ML/uIhfNvbh8j+7ybKrMjPpxvdz41uGZ5sUem6eIxqMLO4DzEkirocA tnW8mCH0m+QqJ08tou23Ev8pdI1umeA+CHU/2+fERS3mpvK0gdOk7ASEy5i7hnlpPql4 xJsQ== X-Gm-Message-State: AOAM530srGGrOHqGMluDlBh+C9ketCGt+6KJJykJE+mx0Gd1kefPFw2M LPF1X5eCFFvifqU23+bgRJlObKxVTZ9QQg== X-Received: by 2002:a17:902:b28a:: with SMTP id u10mr11985726plr.178.1591981611903; Fri, 12 Jun 2020 10:06:51 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h35sm6107361pje.29.2020.06.12.10.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2020 10:06:51 -0700 (PDT) Date: Fri, 12 Jun 2020 10:06:49 -0700 From: Kees Cook To: Peter Zijlstra Cc: Xiaoming Ni , paul@paul-moore.com, edumazet@google.com, paulmck@kernel.org, dhowells@redhat.com, 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: <202006121001.149B5D20C5@keescook> References: <1591957695-118312-1-git-send-email-nixiaoming@huawei.com> <20200612163345.GF2497@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200612163345.GF2497@hirez.programming.kicks-ass.net> 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:33:45PM +0200, Peter Zijlstra wrote: > 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. I thought these had been applied already, I guess not: https://lore.kernel.org/lkml/20190306110549.7628-1-elena.reshetova@intel.com/ Can we try again? -- Kees Cook