From patchwork Wed Feb 22 22:54:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Stancek X-Patchwork-Id: 9587533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 258F5600CA for ; Wed, 22 Feb 2017 22:55:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1569D2864F for ; Wed, 22 Feb 2017 22:55:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A52E286D0; Wed, 22 Feb 2017 22:55:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC5B2864F for ; Wed, 22 Feb 2017 22:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934148AbdBVWyy (ORCPT ); Wed, 22 Feb 2017 17:54:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45014 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933999AbdBVWym (ORCPT ); Wed, 22 Feb 2017 17:54:42 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C24A88046A; Wed, 22 Feb 2017 22:54:42 +0000 (UTC) Received: from dustball.brq.redhat.com (dustball.brq.redhat.com [10.34.26.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75DA0ACBA2; Wed, 22 Feb 2017 22:54:41 +0000 (UTC) From: Jan Stancek To: dhowells@redhat.com Cc: linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, jstancek@redhat.com, bcodding@redhat.com, asavkov@redhat.com Subject: [PATCH 1/2] KEYS: add user_key_payload_rcu() Date: Wed, 22 Feb 2017 23:54:26 +0100 Message-Id: <9b3fac1a82d8aa6b756a73ecded9655cc80f72b0.1487802542.git.jstancek@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 22 Feb 2017 22:54:42 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP user_key_payload() is wrapper for rcu_dereference_protected(), and can't be used with just rcu_read_lock() held. This patch adds user_key_payload_rcu() for accessing key payload in RCU read-side section, without the need to hold key semaphore. Signed-off-by: Jan Stancek --- Documentation/security/keys.txt | 5 +++++ include/keys/user-type.h | 5 +++++ include/linux/key.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt index 3849814bfe6d..da89a854edd2 100644 --- a/Documentation/security/keys.txt +++ b/Documentation/security/keys.txt @@ -1152,8 +1152,13 @@ access the data: wrap the RCU calls to this element: rcu_assign_keypointer(struct key *key, void *data); + + /* access payload with semaphore held */ void *rcu_dereference_key(struct key *key); + /* access payload in RCU read-side section*/ + void *rcu_read_dereference_key(struct key *key); + =================== DEFINING A KEY TYPE diff --git a/include/keys/user-type.h b/include/keys/user-type.h index c56fef40f53e..521bf3369904 100644 --- a/include/keys/user-type.h +++ b/include/keys/user-type.h @@ -53,6 +53,11 @@ static inline const struct user_key_payload *user_key_payload(const struct key * return (struct user_key_payload *)rcu_dereference_key(key); } +static inline const struct user_key_payload *user_key_payload_rcu(const struct key *key) +{ + return (struct user_key_payload *)rcu_read_dereference_key(key); +} + #endif /* CONFIG_KEYS */ #endif /* _KEYS_USER_TYPE_H */ diff --git a/include/linux/key.h b/include/linux/key.h index 722914798f37..b6a8c5896761 100644 --- a/include/linux/key.h +++ b/include/linux/key.h @@ -358,6 +358,9 @@ static inline bool key_is_instantiated(const struct key *key) (rcu_dereference_protected((KEY)->payload.rcu_data0, \ rwsem_is_locked(&((struct key *)(KEY))->sem))) +#define rcu_read_dereference_key(KEY) \ + (rcu_dereference((KEY)->payload.rcu_data0)) + #define rcu_assign_keypointer(KEY, PAYLOAD) \ do { \ rcu_assign_pointer((KEY)->payload.rcu_data0, (PAYLOAD)); \