Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp917464imj; Fri, 15 Feb 2019 08:56:54 -0800 (PST) X-Google-Smtp-Source: AHgI3IZlSzA+R9uhzMJrSzAQYUfAOucgWYMLDx+Gajv58saCCihrhtk5RgUvy1wBQU8+vUYcPlj8 X-Received: by 2002:a63:6184:: with SMTP id v126mr6224112pgb.277.1550249814232; Fri, 15 Feb 2019 08:56:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550249814; cv=none; d=google.com; s=arc-20160816; b=jdCKFv1uEqKQeQyxeI/0FEu/pgZtj+7elAvKGhpe8KY2MOo+Huwl+eONLYptOboCH5 n6V9BkXusa4lJAYJh3cB7d1/xR6jHj918g00mdO+3/4cJ/7CY+Dzf4aMlicNKwsyvkfm Ew8GGoFD5nD2LCo9wvGiuX+9/CYPhBehAIzDHuMaXdogF4YrBqWEQDarg1wBxPLgKzXt /+0u5lVqfdEWl4mErGoPYm6fXuZGgPlmpYYi5+mlmygTiGUZZV+9l7SexJfRqQTw/O+P bwAiW1XQtqkWGeiI5liMIfMfdpHHbh0uA56H9qIfPXOuJap9mAZl1AFEOYeIPaJuwIGv 3Z0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=Ns0TvEr9L+kPJd6lvAOC6hOgIkb1LWzskwdE+voH1d8=; b=Y2Xn/qG2LK6bsJ77WKSg1xZHEUXx5ERJzRxOmbTxdRSmlp11/6cVLQs/k4srEVXY8J 4fiMN4ESXvumhxClvn6aeF6zg0mLHZsLURqEFheqStlMMolptaxIYWLJrZPBsES+9eI2 vArr89+rbH6Nne+KfF7vzPwNAIi0i2G1qweWvqWeNOLSvs116Eom7q+D+smbV0DOnqhz ke5/47OJhVsRMMzTpDFZaRFB5hQebAqrrTEL858XmKIIEUlimjig3iFed6dPfygeDjPu ZH48Uxe5h27GBsZburX/kKFl/MydWk2HYQgaNl1mFHmForp+O+KwDjWZ8swyXem3iy8a GcGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si5667462pgv.499.2019.02.15.08.56.38; Fri, 15 Feb 2019 08:56:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392307AbfBOQL1 (ORCPT + 99 others); Fri, 15 Feb 2019 11:11:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45160 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392282AbfBOQLZ (ORCPT ); Fri, 15 Feb 2019 11:11:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23CFBC0B2A2F; Fri, 15 Feb 2019 16:11:25 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-129.rdu2.redhat.com [10.10.121.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 509715BBA4; Fri, 15 Feb 2019 16:11:23 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [RFC PATCH 21/27] keys: Fix request_key() lack of Link perm check on found key From: David Howells To: keyrings@vger.kernel.org, trond.myklebust@hammerspace.com, sfrench@samba.org Cc: linux-security-module@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, rgb@redhat.com, dhowells@redhat.com, linux-kernel@vger.kernel.org Date: Fri, 15 Feb 2019 16:11:22 +0000 Message-ID: <155024708261.21651.15380024848711404052.stgit@warthog.procyon.org.uk> In-Reply-To: <155024683432.21651.14153938339749694146.stgit@warthog.procyon.org.uk> References: <155024683432.21651.14153938339749694146.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 15 Feb 2019 16:11:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The request_key() syscall allows a process to gain access to the 'possessor' permits of any key that grants it Search permission by virtue of request_key() not checking whether a key it finds grants Link permission to the caller. Signed-off-by: David Howells --- security/keys/request_key.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/security/keys/request_key.c b/security/keys/request_key.c index ab1f6de9e623..10244b6fbf5d 100644 --- a/security/keys/request_key.c +++ b/security/keys/request_key.c @@ -564,6 +564,16 @@ struct key *request_key_and_link(struct key_type *type, key_ref = search_process_keyrings(&ctx); if (!IS_ERR(key_ref)) { + if (dest_keyring) { + ret = key_task_permission(key_ref, current_cred(), + KEY_NEED_LINK); + if (ret < 0) { + key_ref_put(key_ref); + key = ERR_PTR(ret); + goto error_free; + } + } + key = key_ref_to_ptr(key_ref); if (dest_keyring) { ret = key_link(dest_keyring, key);