Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2772521imj; Mon, 11 Feb 2019 08:14:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+QvxEIVzUlCGFaQDpSA4JIsV7ZHPHkhEmORRyVvPsrGZrvtJ9P+3ZTGRiY9uM0Si5fMNQ X-Received: by 2002:a63:d5f:: with SMTP id 31mr6914963pgn.274.1549901661328; Mon, 11 Feb 2019 08:14:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901661; cv=none; d=google.com; s=arc-20160816; b=es210booo2oa5fYdj4DMaJutrj1BYpzgKnudb6RinTu2a4oNFac3+4P/AnVZgEqJP/ wlUKHGP2lPDJm2F79K6UoDrC5EgNg39hMdL963ZWlUaX8sqWQByKy7n5NIXo0i6O0nDK xsyjHd02lsGa4zC2gcZtiFYZq3+gAZFtX0i8c5qroTgZXG20ZJMrPd5oZVrmPlsqUAU6 wiTO0GIcH9TkTDMgiTteSQHj5qt5jdjNQsrhSUXQRenl9YUUKvsL48EyefDO77ZMXByF pkn6sU5XU9h9jX5W2p9QR907+XRnOtypt3haKLdNoMppuTFwE2OfAxagryCjB7OAbXPi YFdw== 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:subject:cc:to :from:dkim-signature; bh=KgXrSAvZCPJLTChjlHFwpwAfFZUWFy3/CWutn4gMp/g=; b=N0M0jOi1/sQMl6u5fyfJob/f7ZnvUvMAxJ+2Z+hJCjz7Ce7YyYGpoqIsePIVDWuBmY wfCnW0JYDppqjyyXYaLnSNYsZoifl631k+n4X4WR8YQEuYlmtHtEa7+Uew+1DzNplKFd 8g/Sicsa4V2CMRgr+kvyttSrOc29m+ehr4Kvw/kvu4WwhlXlawdwYyy5xYkT/YuLzDEm Ele2H951wii0XWWEPhAqJVLBo8YEnGmXMpV1Nx7FnPqxZGCJVD8pKvVZbnsLwWC8/d1U eComOd3K0SQbgi8rMf61bwFP8ql/DG+dqSvhx9GHDszBB7eHKje4zUIDx7GIPM+NOJw3 IJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fZ0rEAjE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l15si9077075pff.206.2019.02.11.08.14.03; Mon, 11 Feb 2019 08:14:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=fZ0rEAjE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730187AbfBKQKs (ORCPT + 99 others); Mon, 11 Feb 2019 11:10:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:59470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729444AbfBKOZv (ORCPT ); Mon, 11 Feb 2019 09:25:51 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4871320821; Mon, 11 Feb 2019 14:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895150; bh=Hq+PdFLa8NtDfCwU8xNrbiBC+DprwABcOKDoZPniabw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZ0rEAjE70JkAUoxwdQ9OwJKxk2kLiWcdBWC0JduPI0SUinCzeCdR5guw9OMlNejk vfz+DuLxqs+t1cTfn63by3TRMgZKDgTx1Iat0S9yljt6jRz4gjFFluDo5NFp9LB50b I5zXIlA471IT1kTGYNSS9lylbUY3ndd/HTGDlt8Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zoran Markovic , Casey Schaufler , James Morris , "Serge E. Hallyn" , Sasha Levin Subject: [PATCH 4.20 108/352] smack: fix access permissions for keyring Date: Mon, 11 Feb 2019 15:15:35 +0100 Message-Id: <20190211141852.668113500@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 5b841bfab695e3b8ae793172a9ff7990f99cc3e2 ] Function smack_key_permission() only issues smack requests for the following operations: - KEY_NEED_READ (issues MAY_READ) - KEY_NEED_WRITE (issues MAY_WRITE) - KEY_NEED_LINK (issues MAY_WRITE) - KEY_NEED_SETATTR (issues MAY_WRITE) A blank smack request is issued in all other cases, resulting in smack access being granted if there is any rule defined between subject and object, or denied with -EACCES otherwise. Request MAY_READ access for KEY_NEED_SEARCH and KEY_NEED_VIEW. Fix the logic in the unlikely case when both MAY_READ and MAY_WRITE are needed. Validate access permission field for valid contents. Signed-off-by: Zoran Markovic Signed-off-by: Casey Schaufler Cc: Casey Schaufler Cc: James Morris Cc: "Serge E. Hallyn" Signed-off-by: Sasha Levin --- security/smack/smack_lsm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 81fb4c1631e9..cd720c06b78c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4333,6 +4333,12 @@ static int smack_key_permission(key_ref_t key_ref, int request = 0; int rc; + /* + * Validate requested permissions + */ + if (perm & ~KEY_NEED_ALL) + return -EINVAL; + keyp = key_ref_to_ptr(key_ref); if (keyp == NULL) return -EINVAL; @@ -4356,10 +4362,10 @@ static int smack_key_permission(key_ref_t key_ref, ad.a.u.key_struct.key = keyp->serial; ad.a.u.key_struct.key_desc = keyp->description; #endif - if (perm & KEY_NEED_READ) - request = MAY_READ; + if (perm & (KEY_NEED_READ | KEY_NEED_SEARCH | KEY_NEED_VIEW)) + request |= MAY_READ; if (perm & (KEY_NEED_WRITE | KEY_NEED_LINK | KEY_NEED_SETATTR)) - request = MAY_WRITE; + request |= MAY_WRITE; rc = smk_access(tkp, keyp->security, request, &ad); rc = smk_bu_note("key access", tkp, keyp->security, request, rc); return rc; -- 2.19.1