Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1380417ybb; Wed, 1 Apr 2020 22:58:13 -0700 (PDT) X-Google-Smtp-Source: APiQypInTE4cDltf96yiPrr0dJcgYaPzCH6IiA6EgTSY8wezldnIlcrMFpslwtxISochB5Dc7qYN X-Received: by 2002:a4a:8041:: with SMTP id y1mr1420124oof.65.1585807093208; Wed, 01 Apr 2020 22:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585807093; cv=none; d=google.com; s=arc-20160816; b=YiNYN4adlohrumFauqjoIYUjrZlOODbOwuQuJ1I9X1omBCpPyEeRVFcoym1GGSxG0h 1Y9JGgjKGNHdJVo6JPVZtOZzYHblZ4cpbhfz2JnwM2ptBc38j2gU31VMPzxzangUpmcG ne/sU1T175MOmOgEw+7MtC48qhq3mWjmeaYp7tnDULT9P0JFXPuPQB7/+5j7747Eh91e oWqYP+tpmPgkws+4OKzTKR5vDD2UYnierI3H8V3F5NLgM+PYh9pFQrUWTHJNsTrq/qHV Z/eQE1HQF22kjprwhAkJE9bnrzLGDHo2C50DFgLlKsei1Qln3gxeqQX9ueRv2Mz1JxgG 2hiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5zQQHlAdkKi/5/LHbljBLnmP/SWJe90/jtmz6ntc02A=; b=l58mkk3DXd73sGDq4h8hLtginOXQ0ID29j2w0W3n1ojG1nOEWN9VViSXTtpQbUvJz1 QhN35od2BnaiRldfZUhfVLBMlasJu0d+HvHdRVgtziXDjyXvD029rkUeBr8CutL8IWV5 GEnzmlqVfpBb2RfB+UXe8iuo83npa0MCGRris6T+girbr1TcMraBm64zzLVKMoMIese3 OgtqNqKtwdUder75eMls9I5ZM7wgMX5GTRmDL0X1M0PytiFrBrKYAgZFrGj8vfqXKtai d/oxprCUPq1ux+pOQ7xOia/Bh3whlderdDlBjluVQTOurYySulRAehChbzhu6n2CS+6U 93uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vKP+S4rd; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si1828565ote.129.2020.04.01.22.57.59; Wed, 01 Apr 2020 22:58:13 -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=fail header.i=@gmail.com header.s=20161025 header.b=vKP+S4rd; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728887AbgDBF52 (ORCPT + 99 others); Thu, 2 Apr 2020 01:57:28 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:53160 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbgDBF52 (ORCPT ); Thu, 2 Apr 2020 01:57:28 -0400 Received: by mail-pj1-f65.google.com with SMTP id ng8so1115095pjb.2 for ; Wed, 01 Apr 2020 22:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5zQQHlAdkKi/5/LHbljBLnmP/SWJe90/jtmz6ntc02A=; b=vKP+S4rdrk3RFrr58T+aSCG4j40KYwNWTXW33a5c5FSl/Eu2lTdZDRL3d8k15FffOK x/X+jXgt2DWtlLZl0+J8oEJIz1eizTOdyfwwTugra+NZ7U2A3EJIcchzjragpfXhTgtf ZRpKdHlH3nKdxlJjZ7A2zcCmgqzWgM63k8oJH/jLEtQCFg9M1SB4xWNYt0ytbkd0Gfpp FM4le5f3s8+scGjcgOg4Mx35mLdFWD6/v0M8UGKgZNukQn/Wfz67onzsR2LiPbVZffKv 9nWWe5pRx+UM2QRpHodRyxL5PLEHe5eYikPolhEord7zXqUYPaWfrErk4hd1/xqzE0ry gkHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5zQQHlAdkKi/5/LHbljBLnmP/SWJe90/jtmz6ntc02A=; b=S+SuQJNK3TrwP6Lv0QRyanlJgruhLXprmj9CESf7JjErTw4SgZKvF6Lwr2aTw5Y1Us rTDx0B+O6qGomqJYd6PRR3nSPehA6jyfL0OO3CenL6N8Cr+ebK6XtcMx7OIMKY3/HI6i k+TgSpnppdh1+68Z8CK6k3rPFssjgHuDeFqs3E7u9+da3OKFIwfYaxXqai1dC0/MFB3g GDbrvdvdsbXVSl5MFQyhCTaE+iG2hUCcucn1ZoW13n5FMeVnFvC+pLZk16ymar7GnzHT gvV2lN/s6yqHMOAUIc+gMJGL9uhZmsrYRQ3Ciiu7tA3mBwbLMANWW9bM4NEQFRGKFKFO juPw== X-Gm-Message-State: AGi0PuZHloqHkC/BjO04G1F1M4X9sAx8uto0E6Fgb+Sp17JXSS9oRoW3 0TdxpY4XGvLUjNEv3h2qO/M= X-Received: by 2002:a17:902:7581:: with SMTP id j1mr1461361pll.171.1585807046892; Wed, 01 Apr 2020 22:57:26 -0700 (PDT) Received: from localhost.localdomain ([103.87.57.161]) by smtp.googlemail.com with ESMTPSA id 207sm2776058pgg.19.2020.04.01.22.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 22:57:26 -0700 (PDT) From: Amol Grover To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , James Morris , Thomas Gleixner , Peter Zijlstra , Jann Horn , David Howells , Shakeel Butt , "Eric W . Biederman" , Andrew Morton , Paul Moore , Eric Paris Cc: linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com, Joel Fernandes , Madhuparna Bhowmik , "Paul E . McKenney" , Amol Grover Subject: [PATCH 2/3 RESEND] cred: Do not use RCU primitives to access cred pointer Date: Thu, 2 Apr 2020 11:26:39 +0530 Message-Id: <20200402055640.6677-2-frextrite@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200402055640.6677-1-frextrite@gmail.com> References: <20200402055640.6677-1-frextrite@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since task_struct::cred can only be used task-synchronously, and is not visible to other threads under RCU context, we do not require RCU primitives to read/write to it and incur heavy barriers. Suggested-by: Jann Horn Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) Signed-off-by: Amol Grover --- include/linux/cred.h | 5 ++--- kernel/cred.c | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index 18639c069263..5973791e5fe4 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -291,11 +291,10 @@ static inline void put_cred(const struct cred *_cred) /** * current_cred - Access the current task's subjective credentials * - * Access the subjective credentials of the current task. RCU-safe, - * since nobody else can modify it. + * Access the subjective credentials of the current task. */ #define current_cred() \ - rcu_dereference_protected(current->cred, 1) + (current->cred) /** * current_real_cred - Access the current task's objective credentials diff --git a/kernel/cred.c b/kernel/cred.c index 809a985b1793..3956c31d068d 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -485,7 +485,7 @@ int commit_creds(struct cred *new) if (new->user != old->user) atomic_inc(&new->user->processes); rcu_assign_pointer(task->real_cred, new); - rcu_assign_pointer(task->cred, new); + task->cred = new; if (new->user != old->user) atomic_dec(&old->user->processes); alter_cred_subscribers(old, -2); @@ -562,7 +562,7 @@ const struct cred *override_creds(const struct cred *new) */ get_new_cred((struct cred *)new); alter_cred_subscribers(new, 1); - rcu_assign_pointer(current->cred, new); + current->cred = new; alter_cred_subscribers(old, -1); kdebug("override_creds() = %p{%d,%d}", old, @@ -590,7 +590,7 @@ void revert_creds(const struct cred *old) validate_creds(old); validate_creds(override); alter_cred_subscribers(old, 1); - rcu_assign_pointer(current->cred, old); + current->cred = old; alter_cred_subscribers(override, -1); put_cred(override); } -- 2.24.1