From patchwork Mon Oct 9 19:40:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9994145 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 9A7DE60216 for ; Mon, 9 Oct 2017 19:42:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C33D28847 for ; Mon, 9 Oct 2017 19:42:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87CCB287B3; Mon, 9 Oct 2017 19:42:00 +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 44D42288FC for ; Mon, 9 Oct 2017 19:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755207AbdJITlP (ORCPT ); Mon, 9 Oct 2017 15:41:15 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38732 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754497AbdJITlO (ORCPT ); Mon, 9 Oct 2017 15:41:14 -0400 Received: by mail-pf0-f195.google.com with SMTP id a7so29997959pfj.5; Mon, 09 Oct 2017 12:41:14 -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; bh=HdzDwyIycjI1kbQLpNGbqpbB3evhH4YDzjszwyu4FVI=; b=XFSBrznjquLmBhlsINss3FvD2FjX6W9olb1zK+S1EdHORDCYgDTjtw6hxVduVmF+UC g1Kd8wmPste718LvCZd7RCvP0OA3Vwls5WNG/OUe04/QCuEMqu/KPpd1AHZbdPewhHPp bBb+LPlFaD+jf6cl+39xY9jiaOAtJaLF2mpvvqaQ06qpp+dAGOhIyHkw7m1eb3PBVhi3 A+pzts9T3PyoTZSTTLwyyqShHOcNLcE6p4erMY52NZSeRkwU9/UJeG6azqXT6y8ukLbA F/A0qTZ/fRy1YjWFfAw5gPm9cHZ0r0er2wTeL8hOBM5LI+ENAR+JmhzV9BVIyiKtE9yi G15w== 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; bh=HdzDwyIycjI1kbQLpNGbqpbB3evhH4YDzjszwyu4FVI=; b=Fjgotj5w2OP1dlI/09oYZyDkSun/NOIuCi4k3t6UtwzrmEetwXb+f1ijDKAhV+z2D5 /hgZlqQJNANQ2kZe/2TAbCiZT1oCjEmSL5v0xgVLxdSarnQSYWqXsLKWbSVafMrgRc5s 37e0jR1Srr+Wky3qTuT+VHV+H24BOEiNxUkZvqatmNtYoEYz97WP/jOpGXl4cFw0v7ss OrbUiIVu+nrD3Eg4VwR6V8FskzzmseeNvq+p2yqr82oa5XBxOMegHbom3mUGSVImR20D kj0KffWPHVr24LZjfSv4rY76DlNaL51Z6mgS6rtWKJghhvB5kD8Xo1UnfERmyp1/9r5s E1OQ== X-Gm-Message-State: AMCzsaUrQQokkTprZBUPGcsrtNWlsakeuwZO2lmEYIOWMqiiOog+iaV9 xChHuxC5GYvW/sdY1mlakGg= X-Google-Smtp-Source: AOwi7QBxmfUA7wn/kxS/O60X/dK0Hg4GsB9Tps0jyxVrORO0Y2X2O/n8N5hchZnnNWxniiDzDtebeA== X-Received: by 10.98.133.4 with SMTP id u4mr11181811pfd.79.1507578074199; Mon, 09 Oct 2017 12:41:14 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81]) by smtp.gmail.com with ESMTPSA id u8sm15860096pgp.17.2017.10.09.12.41.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 12:41:13 -0700 (PDT) From: Eric Biggers To: linux-cachefs@redhat.com, David Howells Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, Eric Biggers , stable@vger.kernel.org Subject: [PATCH v2] FS-Cache: fix dereference of NULL user_key_payload Date: Mon, 9 Oct 2017 12:40:00 -0700 Message-Id: <20171009194000.66958-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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") Reviewed-by: James Morris Cc: [v2.6.32+] Signed-off-by: Eric Biggers --- Changed since v1: added Reviewed-by and resent as standalone patch. Can this please be taken through the keyrings tree? 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--) {