Received: by 10.223.176.5 with SMTP id f5csp877518wra; Tue, 30 Jan 2018 21:19:07 -0800 (PST) X-Google-Smtp-Source: AH8x226LkE/nzEOywFD9OpNe4LonL2xiPHeSgUlwt4qGgZTh1CLKdwBG4q2ieEK93xvTA6eWBdVp X-Received: by 10.99.113.67 with SMTP id b3mr21841546pgn.134.1517375947640; Tue, 30 Jan 2018 21:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517375947; cv=none; d=google.com; s=arc-20160816; b=myUQarhfLzzIvL6b2pi5nnD7jfE4elF73n5ObZZ3rrOEgn1/yJrQU2tX7EM1zMbwop UQsuvSuDhRNWY8cEkSLTq1CxpW+diInB0YONN5YOFDE6aFcKDxc+Gu7qrKK7bWpsWXSS M92GO4XtrAaFMF5Dov6EEeTtpiVsFd2lw5l/4/Z2uFDA2Uj86eeYKhrzExP3gfNV38jz pVuXV3CDpfWM0UU9vFQk4KJqSY8siAewL87YZK1mwKQeV0jF43TmhLEXk505ovhZazYs oy97JmnXYsGZgjyEpBaSQU52ksUAfebDhRloxL8eyvw6ugil7aN5oLBi1d1TXm04Nq/n g2Uw== 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 :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=uW1vta4fo/fOE0AMi4J17fng26XmJDqilltMPnU7nNQ=; b=H8XgsNGyEkgmtTgWdtfmgFRZnC0m64D4WEK1dDFiuKOocHJQiEwmXHOMXbt2nsVRz5 qvX2Xj2ZBBZ3+ZGE1vb3pWKVggP8e0pZIcCiDOpfPQ7zS8+3xNjnYFwT5bIZRfE9NoyP lkf+sAByAz57W35Hi6ES5lZ4GwgRWe8W+ATpeoM44wYRLbt1C5NcCiktkx9Ac1odleSl HSJX/OrGhyIByiGyy5hp6kcZuKufDyqBM+HeblscNJDwpQ/YbO/+LIgh4hcMSaMvTHCM wOCgGR/oJ6It9SZ4S7B1JpCZgzPHMJIFy3C0hlzGSYdh7XgiVZLguKrSx2E7619t/+KN SXrg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si3276360pla.387.2018.01.30.21.18.53; Tue, 30 Jan 2018 21:19:07 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752445AbeAaFQs (ORCPT + 99 others); Wed, 31 Jan 2018 00:16:48 -0500 Received: from mx2.suse.de ([195.135.220.15]:35068 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752321AbeAaFQo (ORCPT ); Wed, 31 Jan 2018 00:16:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DB805AB40; Wed, 31 Jan 2018 05:16:42 +0000 (UTC) From: NeilBrown To: David Howells , Andrew Morton , Ingo Molnar , Anna Schumaker Date: Wed, 31 Jan 2018 16:15:39 +1100 Subject: [PATCH 2/4] cred: add get_cred_rcu() Cc: NFS , lkml Message-ID: <151737573951.14845.5608065682472518930.stgit@noble> In-Reply-To: <151737571564.14845.2874586176125198504.stgit@noble> References: <151737571564.14845.2874586176125198504.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes we want to opportunistically get a ref to a cred in an rcu_read_lock protected section. get_task_cred() does this, and NFS does as similar thing with its own credential structures. To prepare for NFS converting to use 'struct cred' more uniformly, define get_cred_rcu(), and use it in get_task_cred(). Signed-off-by: NeilBrown --- include/linux/cred.h | 11 +++++++++++ kernel/cred.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index 6dd51e503f23..69ed76f7d49f 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -247,6 +247,17 @@ static inline const struct cred *get_cred(const struct cred *cred) return get_new_cred(nonconst_cred); } +static inline const struct cred *get_cred_rcu(const struct cred *cred) +{ + struct cred *nonconst_cred = (struct cred *) cred; + if (!cred) + return NULL; + if (!atomic_inc_not_zero(&nonconst_cred->usage)) + return NULL; + validate_creds(cred); + return cred; +} + /** * put_cred - Release a reference to a set of credentials * @cred: The credentials to release diff --git a/kernel/cred.c b/kernel/cred.c index 4ce75c6fb752..f11aa4e0d2b9 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -195,7 +195,7 @@ const struct cred *get_task_cred(struct task_struct *task) do { cred = __task_cred((task)); BUG_ON(!cred); - } while (!atomic_inc_not_zero(&((struct cred *)cred)->usage)); + } while (!get_cred_rcu(cred)); rcu_read_unlock(); return cred;