From patchwork Thu Sep 28 21:25:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9976773 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 CCB4860375 for ; Thu, 28 Sep 2017 21:30:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEC512975B for ; Thu, 28 Sep 2017 21:30:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3A1929759; Thu, 28 Sep 2017 21:30:28 +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 6DBAB29759 for ; Thu, 28 Sep 2017 21:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751814AbdI1V3w (ORCPT ); Thu, 28 Sep 2017 17:29:52 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34728 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751438AbdI1V3s (ORCPT ); Thu, 28 Sep 2017 17:29:48 -0400 Received: by mail-pf0-f194.google.com with SMTP id g65so2503427pfe.1; Thu, 28 Sep 2017 14:29:47 -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=tcBcb50OghY8dPSINe/CcD4/uODiJSpEuvF2hAWdrqo=; b=EccupiA8ib4/sX8LtvfKkbF5OpQO9jzaesaB40f9OEHNJjxo16VuHxs2djDEQZojXW 6fNjCz/KO+6/qmDSKqdPt8+3xpLOe7WlRWQ9sjPsXZjOl/iXBrIZzRoSSo4GiPjItthK 8UgSV53/AlituNNOUkDmrwtrWmlOY7TrOiyPP8RqQlXY3ClYX8h/CGsnsqnXTgXurelT 89RIQcBW12B9myXei3VuT44SZuw09EkqB8z0U8BUj883Al4DK0RRfdIjN7C7VJtld49X 5oyxosY4MRb17Nt7pdfKLGlSzLEh25mITReNh8zbXedFwninxBycmpxwc2iyGbSvCPZ8 rnZQ== 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=tcBcb50OghY8dPSINe/CcD4/uODiJSpEuvF2hAWdrqo=; b=Nf9pvSvhuNka731VzewYFZksLKDKBUGQskB5zjV77ithoSJzy6YLypR/avOUCcqRc3 VJmlKD9vH/KYZO0xvjNq7WLiIMD+UucV5ABtGV5f4OsySpMJR5X/lT4SHfZZV7CfnPQI KT2VJzM+XnEtqLmP3lJr4xXbVTjz4ffhyzKoNWyyttYyL734XNyFX2S9sLhtEqums0Ks rFx8IdYFAR3xqulo9lIIjEdICzw6YzpPePQg2Rs/Tuia2f6BPBrTOUs7skI2UjQCQjg/ 6W2sBI6GLnp0tSZ4aMGcGynLIu46IrK5Tu1AYoJGMivTND1Z0XG6E17QEBCX6/3D6fy5 egiQ== X-Gm-Message-State: AHPjjUgqCYbs2fSEhYsUAHGy3b/1IAKfPnAlxEcCq+ZKud/pzmUSEUaD ChBGmcH+XSb3WckTGRa6LnF3XprS X-Google-Smtp-Source: AOwi7QChnfamR068ggtJtu5SrCQ+w0wVJBiwRwJcoKfZFoZcB6abHTELZ1R+smkfNHzUg+qR9c3WaA== X-Received: by 10.98.196.206 with SMTP id h75mr5573441pfk.55.1506634187111; Thu, 28 Sep 2017 14:29:47 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id o128sm3810672pga.5.2017.09.28.14.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Sep 2017 14:29:46 -0700 (PDT) From: Eric Biggers To: keyrings@vger.kernel.org Cc: David Howells , Michael Halcrow , linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-security-module@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: [PATCH 2/7] FS-Cache: fix dereference of NULL user_key_payload Date: Thu, 28 Sep 2017 14:25:57 -0700 Message-Id: <20170928212602.41744-3-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.822.g60be5d43e6-goog In-Reply-To: <20170928212602.41744-1-ebiggers3@gmail.com> References: <20170928212602.41744-1-ebiggers3@gmail.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers When the file /proc/fs/fscache/objects (available with CONFIG_FSCACHE_OBJECT_LIST=y) is opened, we request a user key with description "fscache:objlist", then access its payload. However, a revoked key has a NULL payload, and we failed to check for this. request_key() *does* skip revoked keys, but there is still a window where the key can be revoked before we access its payload. Fix it by checking for a NULL payload, treating it like a key which was already revoked at the time it was requested. Fixes: 4fbf4291aa15 ("FS-Cache: Allow the current state of all objects to be dumped") Cc: [v2.6.32+] Signed-off-by: Eric Biggers Reviewed-by: James Morris --- fs/fscache/object-list.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c index b5ab06fabc60..0438d4cd91ef 100644 --- a/fs/fscache/object-list.c +++ b/fs/fscache/object-list.c @@ -331,6 +331,13 @@ static void fscache_objlist_config(struct fscache_objlist_data *data) rcu_read_lock(); confkey = user_key_payload_rcu(key); + if (!confkey) { + /* key was revoked */ + rcu_read_unlock(); + key_put(key); + goto no_config; + } + buf = confkey->data; for (len = confkey->datalen - 1; len >= 0; len--) {