From patchwork Tue Sep 26 20:11:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9972669 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 E3DCE602BD for ; Tue, 26 Sep 2017 20:15:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D901D28F99 for ; Tue, 26 Sep 2017 20:15:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDD8928F9C; Tue, 26 Sep 2017 20:15:40 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 8411D28F99 for ; Tue, 26 Sep 2017 20:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032034AbdIZUOg (ORCPT ); Tue, 26 Sep 2017 16:14:36 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:35080 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968766AbdIZUOc (ORCPT ); Tue, 26 Sep 2017 16:14:32 -0400 Received: by mail-pg0-f68.google.com with SMTP id j16so7342199pga.2; Tue, 26 Sep 2017 13:14:31 -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=3/4bELHBFkJpT5Xf78B+MO6OBN013JdoOU0wkmuT1D0=; b=dZJHeUBtePZtJxpxs0rxM5WqWZkQTlI4jeqIrgJfRV4k4xCmlTSw/Oad7B6AZuBuUt 98VvGBCbet3BshmCCwGbPSU3L4F0aaIE38gZJSIlcrt5+Q5WeKKClyDCZwelfpVPMTOG QVE6RFluLz0ZFnglOTZDFqm0rLosl7xMXbUepHIz6bQNDeVQA90docIEd1ejseMFOjFB IVDoMg41Nbs76FrSyip4xXCLSxlUCKgYjOGDR3aTnXGMBaD65+qUQ+6k8AXjbduVnTMm dhI3+G5KIFzv00rC3AbnhAa7pzq2M08RGWHvTELLHUjAfd1XUbv/n3DdAZ5LVnLH61Z+ UywQ== 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=3/4bELHBFkJpT5Xf78B+MO6OBN013JdoOU0wkmuT1D0=; b=qGavPquDJ4/7/lvT4FLbmgeaijzezuKuiBWdKZcxYMubH9xV6BIL48q4Z0UI/Yh8K0 d7dm/qcHmdUsbrHFWzLoGri9qKuvLeCMz2j2LFN+YPI2juY0e8k0LqBS7E/ZLDww76Fh j1vy3p00T1Dw4BZPrnRfKYBDP6whlDyhxynZT3cDNA9Fd78d8vYNBbArzUAlKKK58FdV DQyst9+U7Aw+VdEPSEjNZKfmefqtuGAUFLCFpkQyUclH7UrXWfDsnlUqQZbFD2LTpCXz AFMjulY2CV7FVbNRvAY4JktsZIa37R2poOcwq/8IP/Wj2QrwmRlEMrDFs0tooQbyNkqR ybMg== X-Gm-Message-State: AHPjjUhcqKMdTo7kjvZiQaOed+HOXS1aGJfMN4EqQQ6Sr6rUzRp5pvRV t1M+cYCAi3KG41fy0eEqkbpAO8pW X-Google-Smtp-Source: AOwi7QCXHghlBMxW2oDjE47r1g6Ho6RYcF5lDAVsjWNfDEFiBHFTbDiXjDmAXRsglb3CO2qZgwQCjw== X-Received: by 10.84.217.131 with SMTP id p3mr4093901pli.126.1506456871461; Tue, 26 Sep 2017 13:14:31 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id g68sm16597640pfc.64.2017.09.26.13.14.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 13:14:31 -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 v2 4/6] KEYS: load key flags and expiry time atomically in keyring_search_iterator() Date: Tue, 26 Sep 2017 13:11:03 -0700 Message-Id: <20170926201105.126166-5-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.1.992.g2c7b836f3a-goog In-Reply-To: <20170926201105.126166-1-ebiggers3@gmail.com> References: <20170926201105.126166-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 7fc661f492d3..1dfff0eac474 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);