All of lore.kernel.org
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: jmorris@namei.org, linux-security-module@vger.kernel.org,
	john.johansen@canonical.com, selinux@tycho.nsa.gov,
	keescook@chromium.org, Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH v5] LSM: Multiple concurrent LSMs
Date: Mon, 22 Oct 2012 10:47:32 -0700	[thread overview]
Message-ID: <508586B4.9070802@schaufler-ca.com> (raw)
In-Reply-To: <201210211337.DAF60411.FMHOVSJOQOFtFL@I-love.SAKURA.ne.jp>

On 10/20/2012 9:37 PM, Tetsuo Handa wrote:
> What about adding "struct security_operations *next;" to
> "struct security_operations" like below?

This would address the memory leak introduced by my
version of security_reset_ops.

What is doesn't address is all of the checks to see if
a particular LSM provides a hook. For that there needs
to be a list in each hook. A list per hook would complicate
registration and reset. It would allow cleaner handling
of the capability hooks.

My inclination is to have a shot at making the changes in
security.c to do the lists at that level. It's more work,
but I think it would be a better result.

>
>  struct security_operations {
>  	char name[SECURITY_NAME_MAX + 1];
> + 	int index; /* Index number used by lsm_get_blob()/lsm_set_blob(). */
> + 	struct security_operations *next; /* Next LSM to call if not NULL. */
>  	int foo();
>  	int bar_alloc();
>  	void bar_free();
>  };
>
> I think the basic change looks like
>
>  int security_foo()
>  {
> -	return security_ops->foo();
> +	struct security_operations *ops = security_ops;
> +	for (ops = security_ops; ops; ops = ops->next)
> +		if (ops->foo) {
> +			int rc = ops->foo();
> +			if (rc)
> +				return rc;
> +		}
> +	return 0;

Standard list macros should be used. Not that I think they
add all that much value in this case, but you never know.

I still think that we want to "call all" rather than
"bail on fail".

>  }
>
>  int security_bar_alloc()
>  {
> -	return security_ops->bar_alloc();
> +	int rc;
> +	struct security_operations *ops;
> +	struct security_operations *tmp;
> +	for (ops = security_ops; ops; ops = ops->next)
> +		if (ops->bar_alloc) {
> +			rc = ops->bar_alloc();
> +			if (rc)
> +				goto undo;
> +		}
> +	return 0;
> +undo:
> +	for (tmp = security_ops; tmp != ops; tmp = tmp->next)
> +		if (tmp->bar_free)
> +			tmp->bar_free();
> +	return rc;

Looks about right.

>  }
>
>  void security_bar_free()
>  {
> -	security_ops->bar_free();
> +	struct security_operations *ops;
> +	for (ops = security_ops; ops; ops = ops->next)
> +		if (ops->bar_free)
> +			ops->bar_free();
>  }

Same for any "void" hook.

>
> and unregistration will look like
>
>  int remove_security_ops(struct security_operations *lsm)
>  {
>  	struct security_operations *ops = security_ops;
>  	struct security_operations *prev = ops;
>  	do {
>  		if (ops == lsm) {
>  			prev->next = lsm->next;
>  			return 0;
>  		}
>  		prev = ops;
>  		ops = ops->next;
>  	} while (ops);
>  	return -ENOENT;
>  }

Very clean, but it's not important that this be clean.

>
> and registration will look like
>
>  int add_security_ops(struct security_operations *lsm)
>  {
>  	static int index;
>  	struct security_operations *ops = security_ops;
>  	while (1) {
>  		if (ops == lsm)
>  			return 0;
>  		if (!ops->next)
>  			break;
>  		ops = ops->next;
>  	}
>  	if (index == COMPOSER_MAX - 1)
>  		return -ENOSPC;
>  	lsm->index = index++;
>  	ops->next = lsm;
>  	return 0;
>  }

Plus conflict checking. Again, it's not really important how
clean this operation is.

>
> .
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

      parent reply	other threads:[~2012-10-22 17:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-19 20:07 [PATCH v5] LSM: Multiple concurrent LSMs Casey Schaufler
     [not found] ` <CAGXu5jJKWZMJbX+kQZb1Qe64EjuZMEubCgtiV4COXWo9=hqPiQ@mail.gmail.com>
2012-10-19 21:39   ` Casey Schaufler
     [not found]   ` <201210242225.EFC43782.FLFQMHOOVFJOSt@I-love.SAKURA.ne.jp>
2012-10-24 18:32     ` Casey Schaufler
     [not found]     ` <201210250650.HAJ18213.FMtVQOFHJOLOFS@I-love.SAKURA.ne.jp>
     [not found]       ` <CAGXu5jKdLnDCpDzteY1v3aStAxAezdOykKUN1gDt69BZcBvwEA@mail.gmail.com>
     [not found]         ` <201210252116.DBJ56717.tVFFLJOOOSQHFM@I-love.SAKURA.ne.jp>
     [not found]           ` <201210252128.EGC12919.OFtFSMHQOOVLFJ@I-love.SAKURA.ne.jp>
     [not found]             ` <201210270127.BJF52683.QtMFVOFOLJSFOH@I-love.SAKURA.ne.jp>
2012-10-26 16:52               ` [PATCH v5.1] " Casey Schaufler
     [not found] ` <201210211206.DEI34330.FLFQMtFOOSJOHV@I-love.SAKURA.ne.jp>
2012-10-22 17:16   ` [PATCH v5] " Casey Schaufler
     [not found]   ` <201210211337.DAF60411.FMHOVSJOQOFtFL@I-love.SAKURA.ne.jp>
2012-10-22 17:47     ` Casey Schaufler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=508586B4.9070802@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.