Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3628747imu; Mon, 28 Jan 2019 08:06:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN5+htTcoctd7vkEqlS/wYKLHuYwcl73MxTnchdYm39KYx7ViyNHdzeIwF0yu3RPrk0qO43i X-Received: by 2002:a63:e247:: with SMTP id y7mr19422103pgj.84.1548691572466; Mon, 28 Jan 2019 08:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691572; cv=none; d=google.com; s=arc-20160816; b=oJyLLKHzRHMKsbjWpvGk2oQPKXrBEkWV/nIauhXJpFG66u7BMI5jka8BnoObzFYrT/ BnUqIZyCs3C0AKoT6layJGOFYrIGkcbls28edjMuQKKV+xUHDOnzmcJYFZKf92ZD8BAV hTW++J81gx5A9ndrPhkmlEOq804pHrF2/IxKOoG5/wj7/TaYuJn6Fqtglr3SjWsl75ai 0EEb7IogARMRUch+FpdfUNP5kPnHMjxl26GfbtGRpifjpI9gasoXW/Q6Gl/sFl2AjXGZ bcucnSNyFB//0utHKRX/sC1e3bFOqhdvQiXJJk+ZCssNBHeKLT/ChqNYg9jC/WmcqwxC kwLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zzsQZ4vOohvXAige8KVZOmzczeNmQu23UZFGIJ4iAB0=; b=Bdq2moGLo0zQIzrPyHn87raVch4ujMjGzwazXTOLTJVmbXbpwpqVmu7FEAJ02UImci aNZ9hZWKT2U38ArzcSm+CYfbMA0v1oRhbpV6xVpFG6zTwyAMS1uaF6tmfd6ZPayPZiWK TQ4S6KmogtV8qcgMW8amhHKYCs7eD+VDycpaX86cow5zo5ewhE6XHn+DWsLe8fAcJBKo 4vWRLI3EUaWSPk5IaK/CrOa+j+6VWe6VY7kG/ohORqOE3eW6+9FE/K6QSTLnvrgF4Pnf BjzJrzeWyAKdMJYLNUbFJ4U3NtG/wfUK8U3BLZ8ABplb4ZRPcWoU7ofjp4Cil0XS7Ziu Uqtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1AhmUYpk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si34272972pls.16.2019.01.28.08.05.57; Mon, 28 Jan 2019 08:06:12 -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=1AhmUYpk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731561AbfA1QEW (ORCPT + 99 others); Mon, 28 Jan 2019 11:04:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:49864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731550AbfA1QEV (ORCPT ); Mon, 28 Jan 2019 11:04:21 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A9C7A2184D; Mon, 28 Jan 2019 16:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691461; bh=41BvhBWtOTeFFGZmfcU5CdTz8ga1TmWQcE1yi7m43YU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1AhmUYpkDxx/6bZSQGRIhNnxwYokQ5zlxFbkaTzGJfBNxYxFy7ZQDTxOQZuOta+d6 LqOFIqWNQ2PNS9+FLd4wXxeuRE8lP34ckl0Sc9quQ7ItHmRKJZsGuP0DTvi+wAo9n2 vObX+b2VfaqTsU9V+nETsohUKL9keBDoUThJ2Hz0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zoran Markovic , Casey Schaufler , James Morris , "Serge E. Hallyn" , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 100/258] smack: fix access permissions for keyring Date: Mon, 28 Jan 2019 10:56:46 -0500 Message-Id: <20190128155924.51521-100-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zoran Markovic [ 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 70d3066e69fe..017c47eb795e 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