Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2400444ybi; Mon, 1 Jul 2019 11:20:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzy5881a7CbN41jewrgOFlY1WpLK5430zxo/RGRbWri1dmAjYGMrPo+Q9uHAayDVbgqz97+ X-Received: by 2002:a63:2ad5:: with SMTP id q204mr26415257pgq.140.1562005255146; Mon, 01 Jul 2019 11:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562005255; cv=none; d=google.com; s=arc-20160816; b=byMuRnldTM/eRm9jYN98QzJae63MzUZmpnvp1f9hZ3h4+UROqUvmr1aBPQPK7tkZDh aXDBYGH3nySTLbWdPvvc6fSdux/sLzt74eCKmQsztGNTFP5+EAW/nrqgOclUlObwTbHF v9jYqxoer56GY2k7TwYZjFDmVmIZEbwvcA9Dl39PaNQb5tMwhFuJ48j/3KH7bJG5TxzK gEA7BoyQO31zDqBa8TnFb1sQCpjNO9Xh39kWvXfnRoam15qOBvxeS0a8+Xt9rEqSw0mU /DuPWsfYijwuV1CSTKH+kqPZ+Jd5GW/v9eJqsaYTramq/AUf+img5vpoJDp/nyo5THgM 9+Ag== 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=GaSNs2HPkef+Bju56da9n81KJMEMrMttgso442g/QFQ=; b=H/O5J2T/RbF1HdclVazSD/WZ895qDD3SnN7AqN3Qs2S5z3AUc9X8XnIs4ZiOe/iGGJ T7fg5vF85yOXnG9pYwhN/q1CpwwYEc6TM10ZH6oNAjrnOJBTZwxon0fAlI0cQXkxjdhN GrIZaAhamArJgGRZIIn6Y5XhEbPtGdDbqKMyFlX7YQps8DIB0Xq5vK8pDAgUtUcOqRSw QkTmK6H6m4InvL8ADjTnTmElZwUXyjeHkjDBqDD0w7QpRxJJ6d6wr4vHfRLoMboKgoET AopZsOo35XZRSwsOoN4Ha/3w6QQxTY84pTfdFobY9n0QK2gJoRBQHibwwtNdNw8rZw5m +FKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dDxXBYrf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 65si11172950pff.220.2019.07.01.11.20.39; Mon, 01 Jul 2019 11:20:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dDxXBYrf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729808AbfGARsx (ORCPT + 99 others); Mon, 1 Jul 2019 13:48:53 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:35131 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728152AbfGARsx (ORCPT ); Mon, 1 Jul 2019 13:48:53 -0400 Received: by mail-ot1-f67.google.com with SMTP id j19so14391749otq.2 for ; Mon, 01 Jul 2019 10:48:53 -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=GaSNs2HPkef+Bju56da9n81KJMEMrMttgso442g/QFQ=; b=dDxXBYrffpjFtM2c0mbpgHYAdQWFOMC7Pg5wS3+aSRf27a4WL/vMFFEEX1k0Q+UEoD PxEbvX5YtveVeJbRRR4L+QvEY7JZXKaXWsmDMieqT3Vqa+ldWVs3Crj4SSUSk68x+TMW 4rzGe83wXA28h4lBdWyPq2UXIHWh4/a9tWqhLsEArfRSxVKpx+7/XT7ej0qWYPRmDgX0 jpo5P91s5ji/fLtheR47BG337NnW36xNfAwK8NbTVCjf90H1eMlSEfXst9tbCQD06Zq6 luM/3dSzwvzTENJmBQw3gfDnXPyJUA1OZ0YEU2BaLqSnJ9aKLDmMBpZDG1wWGJe2Gd+V MNVA== 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=GaSNs2HPkef+Bju56da9n81KJMEMrMttgso442g/QFQ=; b=mBVKNgCdKNvVx8VOMswGRw8KBaUTtOo4Tqj5Xb0tgWvMHN840dZ4i62NacVYYgLdfU X72iqCBxK4PUmrHilSevIs/J2YXZZrnNdut+nSRJmk1t+xILL+W0vUlE7Zphmq0mhzQf dVLA/rUm0j0GEOq1AUwBJMPam8c9JCaFwWdfNvMxEj2bogMo/FTOnUeOYfr0Ez9cl2+4 yHvW1hXQy+gweX8JRfqBOpHNHBWQ75O+gEGq1fC0YOeSqHNRyTzS3LIG0gZcB7W24qEs hzwQu9GF30JTFarBGjXo+YqC4xzZ4XHlz1ueI5+NN41+Zpu+9KgX7iI2W4eDGOf0YvqS H/jg== X-Gm-Message-State: APjAAAXPz+F5pPkSyulinRdvZbSRKT1s5UURVEq+3181AxAeT1Lh8ksD Ahs5WNJdXUpnSL+UYgaYNUIuXYtEiJANpJKnQUHKxw== X-Received: by 2002:a9d:2f26:: with SMTP id h35mr21598797otb.183.1562003332560; Mon, 01 Jul 2019 10:48:52 -0700 (PDT) MIME-Version: 1.0 References: <20190628193442.94745-1-joel@joelfernandes.org> In-Reply-To: <20190628193442.94745-1-joel@joelfernandes.org> From: Jann Horn Date: Mon, 1 Jul 2019 19:48:26 +0200 Message-ID: Subject: Re: [PATCH v2] Convert struct pid count to refcount_t To: "Joel Fernandes (Google)" Cc: kernel list , Mathieu Desnoyers , Matthew Wilcox , Peter Zijlstra , Will Deacon , "Paul E . McKenney" , Elena Reshetova , Kees Cook , kernel-team , Kernel Hardening , Andrew Morton , "Eric W. Biederman" , Michal Hocko , Oleg Nesterov , Stephen Rothwell 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 28, 2019 at 9:35 PM Joel Fernandes (Google) wrote: > struct pid's count is an atomic_t field used as a refcount. Use > refcount_t for it which is basically atomic_t but does additional > checking to prevent use-after-free bugs. [...] > struct pid > { > - atomic_t count; > + refcount_t count; [...] > diff --git a/kernel/pid.c b/kernel/pid.c > index 20881598bdfa..89c4849fab5d 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -37,7 +37,7 @@ > #include > #include > #include > -#include > +#include > #include > #include > > @@ -106,8 +106,7 @@ void put_pid(struct pid *pid) init_struct_pid is defined as follows: struct pid init_struct_pid = { .count = ATOMIC_INIT(1), [...] }; This should be changed to REFCOUNT_INIT(1). You should have received a compiler warning about this; I get the following when trying to build with your patch applied: jannh@jannh2:~/git/foreign/linux$ make kernel/pid.o CALL scripts/checksyscalls.sh CALL scripts/atomic/check-atomics.sh DESCEND objtool CC kernel/pid.o kernel/pid.c:44:30: warning: missing braces around initializer [-Wmissing-braces] struct pid init_struct_pid = { ^ kernel/pid.c:44:30: warning: missing braces around initializer [-Wmissing-braces] kernel/pid.c:44:30: warning: missing braces around initializer [-Wmissing-braces] kernel/pid.c:44:30: warning: missing braces around initializer [-Wmissing-braces] kernel/pid.c:44:30: warning: missing braces around initializer [-Wmissing-braces]