Linux-Security-Module Archive on lore.kernel.org
 help / Atom feed
* [RFC PATCH] smack: fix access permissions for keyring
@ 2018-10-17 23:25 Zoran Markovic
  2018-11-27 20:18 ` Casey Schaufler
  0 siblings, 1 reply; 2+ messages in thread
From: Zoran Markovic @ 2018-10-17 23:25 UTC (permalink / raw)
  To: linux-security-module, linux-kernel
  Cc: Zoran Markovic, Casey Schaufler, James Morris, Serge E. Hallyn

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 <zmarkovic@sierrawireless.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: James Morris <jmorris@namei.org>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
---
 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 340fc30..77e405f 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4326,6 +4326,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;
@@ -4349,10 +4355,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.7.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] smack: fix access permissions for keyring
  2018-10-17 23:25 [RFC PATCH] smack: fix access permissions for keyring Zoran Markovic
@ 2018-11-27 20:18 ` Casey Schaufler
  0 siblings, 0 replies; 2+ messages in thread
From: Casey Schaufler @ 2018-11-27 20:18 UTC (permalink / raw)
  To: Zoran Markovic, linux-security-module, linux-kernel
  Cc: James Morris, Serge E. Hallyn

On 10/17/2018 4:25 PM, Zoran Markovic wrote:
> 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.

Do you have any test cases for this?

> Signed-off-by: Zoran Markovic <zmarkovic@sierrawireless.com>
> Cc: Casey Schaufler <casey@schaufler-ca.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: "Serge E. Hallyn" <serge@hallyn.com>
> ---
>  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 340fc30..77e405f 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -4326,6 +4326,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;
> @@ -4349,10 +4355,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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17 23:25 [RFC PATCH] smack: fix access permissions for keyring Zoran Markovic
2018-11-27 20:18 ` Casey Schaufler

Linux-Security-Module Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linux-security-module/0 linux-security-module/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-security-module linux-security-module/ https://lore.kernel.org/linux-security-module \
		linux-security-module@vger.kernel.org linux-security-module@archiver.kernel.org
	public-inbox-index linux-security-module


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-security-module


AGPL code for this site: git clone https://public-inbox.org/ public-inbox