From patchwork Wed Sep 27 19:50:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9974647 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 23EFA60365 for ; Wed, 27 Sep 2017 19:51:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1773E2904B for ; Wed, 27 Sep 2017 19:51:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C34D2930C; Wed, 27 Sep 2017 19:51:49 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 9FB362904B for ; Wed, 27 Sep 2017 19:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751894AbdI0TvT (ORCPT ); Wed, 27 Sep 2017 15:51:19 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:32942 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbdI0TvR (ORCPT ); Wed, 27 Sep 2017 15:51:17 -0400 Received: by mail-pf0-f195.google.com with SMTP id h4so7599558pfk.0; Wed, 27 Sep 2017 12:51:16 -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; bh=Uxk9KDaMiLicqVaGqReShPnveXI882b+pNr7Sk7OIKg=; b=cNNQylP39vt645fgWYtPqJFi3MJe8unIUwzAIMcyd2VsQnPXCBtVm/gcu04skGIyoS V0/DsD82Fe4Q3lAQmSYlIqJsztngPx6vb4CDwwWmeMdvWmtzZkUYg34+InYbHGZg+SiA 8OKPZYbgsLkpfjoEvQ2UcdnQrcTF5PubWc0flKEhuOzdzRVHyDTRgGQ6wvdAczEFIvXq v36XhV4XBSWbDRkZsziyZzRGBiPCsOScBQaxu46J2GJhrW5NJ7U9E66fuzETHdP5VM8N /0UL1Y6fv4baa/uSm7eKXYZ5n0qrbgdm6Vg5J2zOCw9PV/4aAvnQhyLpBoTTcd1RNnQK 3thg== 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; bh=Uxk9KDaMiLicqVaGqReShPnveXI882b+pNr7Sk7OIKg=; b=VKqw4qdzoMfzuiblCMCVBizE8E4Xfzyq6FvabsJ6QQzQcgSa9J0JN8ddFjycMZ/bHg DjrsoE4fXQre+/VkNcsMLc4i8KqqJy64qZtMmEKjxu+WztwPEVXQ0QPrTgSGyxDHC7gP BLc9t+QCE51WHzQYYv01G9onaKZPmwnQKFrIgMwP8ykXWOWb+c9yBgnM17mXQp8NrW+N 9w6BFPLUIBcFMoJTFib+K1b2mlUL9EWBdTW+QI/0D2tPt3VLtrdny8LDTIVWaObttDzX y8vobV3rNGKxLT2nskO+9Q5NqJZKyPDb2GdYvAS5I1izlvPETzFjtmJgM1fsRIKij7Me yTOA== X-Gm-Message-State: AHPjjUjaxKPtMYRlPAJOQRSmm0Rs8vODwidlcI2fYU7Y7ip65MU6qbMD 9TVsyGM+jqwyWnu12PeWwskRNaup X-Google-Smtp-Source: AOwi7QAt9r4kzqv7b11DvlUJhpuBXBH22S97dD1VfkyP0pIKKmeM13jT/WsIXrbJ9JwndZabeBYm1Q== X-Received: by 10.84.216.87 with SMTP id f23mr2073664plj.307.1506541876187; Wed, 27 Sep 2017 12:51:16 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id d5sm24954499pfg.26.2017.09.27.12.51.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Sep 2017 12:51:15 -0700 (PDT) From: Eric Biggers To: keyrings@vger.kernel.org Cc: David Howells , Michael Halcrow , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH v3 5/7] KEYS: load key flags and expiry time atomically in keyring_search_iterator() Date: Wed, 27 Sep 2017 12:50:45 -0700 Message-Id: <20170927195047.122358-6-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.822.g60be5d43e6-goog In-Reply-To: <20170927195047.122358-1-ebiggers3@gmail.com> References: <20170927195047.122358-1-ebiggers3@gmail.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Similar to the case for key_validate(), we should load the key ->flags and ->expiry once atomically in keyring_search_iterator(), since they can be changed concurrently whenever the key semaphore isn't held. Signed-off-by: Eric Biggers --- security/keys/keyring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/security/keys/keyring.c b/security/keys/keyring.c index e54ad0ed7aa4..cb39b517f69c 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c @@ -553,7 +553,7 @@ static int keyring_search_iterator(const void *object, void *iterator_data) { struct keyring_search_context *ctx = iterator_data; const struct key *key = keyring_ptr_to_key(object); - unsigned long kflags = key->flags; + unsigned long kflags = READ_ONCE(key->flags); kenter("{%d}", key->serial); @@ -565,6 +565,8 @@ static int keyring_search_iterator(const void *object, void *iterator_data) /* skip invalidated, revoked and expired keys */ if (ctx->flags & KEYRING_SEARCH_DO_STATE_CHECK) { + time_t expiry = READ_ONCE(key->expiry); + if (kflags & ((1 << KEY_FLAG_INVALIDATED) | (1 << KEY_FLAG_REVOKED))) { ctx->result = ERR_PTR(-EKEYREVOKED); @@ -572,7 +574,7 @@ static int keyring_search_iterator(const void *object, void *iterator_data) goto skipped; } - if (key->expiry && ctx->now.tv_sec >= key->expiry) { + if (expiry && ctx->now.tv_sec >= expiry) { if (!(ctx->flags & KEYRING_SEARCH_SKIP_EXPIRED)) ctx->result = ERR_PTR(-EKEYEXPIRED); kleave(" = %d [expire]", ctx->skipped_ret);