Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2682060imj; Mon, 11 Feb 2019 06:59:00 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib58+KcOh2xeAOYJ+tmlgVB7A7DgmTbSvUBGYEjzrtrX5kTeHngTT252LKidZXtzZJXD5zi X-Received: by 2002:a63:e711:: with SMTP id b17mr22981177pgi.363.1549897140507; Mon, 11 Feb 2019 06:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897140; cv=none; d=google.com; s=arc-20160816; b=wjk58/6L/Blf4kz8Xm8/QyUalgv4upc8Ay1T+goj8CJ/0D83nyaMriUDAjmscv09KE m8kwigp2ua1yztmZFoxFjMV3sUPVKfA7fevRX9rqW51upFnlEqWhthsA//MP4tKXGodL 9MUR36+xuxf4qQkOYZfcFgSpYVQ6UZN2xbUfQE55qMrM3Q09ehGbnOpFtM3mDlWbdySs syXjmQ/U/zI59asJteTaLBEHFnalCMiBtCJdTMVVA6FqBRMTHMDMHhZY1RF86qOw4Bbq gxi+gvTU7OURIhc5YX953HxzKxFfLlr7mL0N/+tm3cObZq9swGJEqZaWwzov20P/+K5R dE+w== 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=s2+zU5us86kAsIugJrnqtV41kpG7v0YT7DK7QFXJLF8=; b=fIfkCXYG/ZHvGXM7xBoOEGmRFCeMxDi4nqnRkNqcYZoEbbS8SrdRfunnCSnLgHgSka WobLvXkdagfHfHjuHBHWgszAiBvo6lC0IJiHmXDp3S0U1dUcNjGmPnhyonZyDDm19cq6 HGXIX2pTRM+ezrTI0bnk+XxTORQwevcLuEwZnfElaRyqUzS1C3l9Xk7aT2d39N7DicEW msgD79O5UCddU2TOjorrG5DZk6Tb+ZgruUxxTpdJyKqhsDcthKulXCakPfnweDx7CvGR vEvTpcGRpXlumZe0Mso6rp5LqdAH+BFeZQBiWhmHP77eQX77hoKUE9BKsPrDi7+Hcp6d 1rkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="iI/tPzjC"; 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 f34si4053436ple.279.2019.02.11.06.58.44; Mon, 11 Feb 2019 06:59:00 -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="iI/tPzjC"; 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 S2389246AbfBKO4v (ORCPT + 99 others); Mon, 11 Feb 2019 09:56:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:44110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388209AbfBKO4s (ORCPT ); Mon, 11 Feb 2019 09:56:48 -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 C67362229E; Mon, 11 Feb 2019 14:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897008; bh=v8E7eboEWnrMsnfgPz2p0rHm+Zyv83+iweSfWKYHx08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iI/tPzjCqdBo1+hNUpOu2z6jOrew/f7trlnLCEwvQO9Yk3IRG0x1JfgasNyahGXf3 oy4dIlH92ffP67DiFYay6MttYbyzAFioZPl1rcTIaFds4807egdCgPxvptmEETwD4m feRADs8E5U474BIe/M7qgBcTFG9THsEPzKiwDnRE= 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.14 061/205] smack: fix access permissions for keyring Date: Mon, 11 Feb 2019 15:17:39 +0100 Message-Id: <20190211141832.794267358@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 c8fd5c10b7c6..0d5ce7190b17 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -4356,6 +4356,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; @@ -4375,10 +4381,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