Linux Container Development
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
Cc: Linux Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: Re: [PATCH 2/4] cr: add generic LSM c/r support (v6)
Date: Mon, 19 Oct 2009 14:02:27 -0500	[thread overview]
Message-ID: <20091019190227.GA7201@us.ibm.com> (raw)
In-Reply-To: <4ADCAC5B.9080205-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>

Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
> > 	oct 19: At checkpoint, we insert the void* security into the
> > 		objhash.  The first time that we do so, we next write out
> > 		the string representation of the context to the checkpoint
> > 		image, along with the value of the objref for the void*
> > 		security, and insert that into the objhash.  Then at
> > 		restart, when we read a LSM context, we read the objref
> > 		which the void* security had at checkpoint, and we then
> > 		insert the string context with that objref as well.
> 
> I hoped to see similar comment inlined in the code.

If we're happy with this approach, then I will add good comments above
security_checkpoint_obj and security_restore_obj, and above the objhash
entries.

> [...]
> 
> > @@ -159,8 +175,12 @@ int checkpoint_file_common(struct ckpt_ctx *ctx, struct file *file,
> >  	if (h->f_credref < 0)
> >  		return h->f_credref;
> >  
> > -	ckpt_debug("file %s credref %d", file->f_dentry->d_name.name,
> > -		h->f_credref);
> > +	ret = checkpoint_file_security(ctx, file, &h->f_secref);
> > +	if (ret < 0)
> > +		return ret;
> 
> How about a ckpt_write_err() here, or in checkpoint_file_security(),
> or in security_checkpoint_obj(), or all of the above.

Yeah, definately, at each of the checkpoint failures I add.

> > +
> > +	ckpt_debug("file %s credref %d secref %d\n",
> > +		file->f_dentry->d_name.name, h->f_credref, h->f_secref);
> 
> [...]
> 
> > @@ -433,6 +464,22 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = {
> >  		.checkpoint = checkpoint_tty,
> >  		.restore = restore_tty,
> >  	},
> > +	/* LSM void *security on objhash - at checkpoint */
> > +	{
> > +		.obj_name = "SECURITY PTR",
> > +		.obj_type = CKPT_OBJ_SECURITY_PTR,
> > +		.ref_drop = obj_no_drop,
> > +		.ref_grab = obj_no_grab,
> > +	},
> 
> I really wish there was a comment explaining why it's ok to not
> drop/grab the reference (because the security is always referenced
> by an object that is itself grabbed, e.g. file, ipc etc ?).

Yes.

> > +	/* LSM security strings - at restart */
> > +	{
> > +		.obj_name = "SECURITY STRING",
> > +		.obj_type = CKPT_OBJ_SECURITY,
> > +		.ref_grab = lsm_string_grab,
> > +		.ref_drop = lsm_string_drop,
> > +		.checkpoint = checkpoint_lsm_string,
> > +		.restore = restore_lsm_string_wrap,
> > +	},
> >  };
> 
> [...]
> 
> > @@ -376,6 +383,16 @@ struct ckpt_hdr_groupinfo {
> >  	__u32 groups[0];
> >  } __attribute__((aligned(8)));
> >  
> > +struct ckpt_hdr_lsm {
> > +	struct ckpt_hdr h;
> > +	__s32 ptrref;
> > +	__u8 sectype;
> > +	__u8 padding;
> 
> I don't think padding is necessary here...

Ok, I'll take it out.

> > +	/*
> > +	 * This is followed by a string of size len+1,
> > +	 * null-terminated
> > +	 */
> > +} __attribute__((aligned(8)));
> 
> [...]
> 
> > +/**
> > + * security_checkpoint_obj - if first checkpoint of this void* security,
> > + * then 1. ask the LSM for a string representing the context, 2. checkpoint
> > + * that string
> > + * @ctx: the checkpoint context
> > + * @security: the void* security being checkpointed
> > + * @sectype: indicates the type of object, because LSMs can (and do) store
> > + * @secref: We return the objref here
> > + * different types of data for different types of objects.
> > + *
> > + * Returns the objref of the checkpointed ckpt_lsm_string representing the
> > + * context, or -error on error.
> > + *
> > + * This is only used at checkpoint of course.
> > + */
> > +int security_checkpoint_obj(struct ckpt_ctx *ctx, void *security,
> > +				int sectype, int *secref)
> 
> This function returns 0 for success or a negative error. It should
> return the @secref instead of passing it by reference (see your
> description of the return value above !)
> 
> [...]

Yes the comment is out of date but the API is imo an improvement.
Note that SECURITY_CTX_NONE, -1, is a meaningful secref, and at
the sametime -EPERM, -1, is conceivably a valid error code (though
at the moment no lsm will return it).

So I think overloading the secref with error codes is wrong here.

> > +	/* Ask the LSM to apply a void*security to the object
> > +	 * based on the checkpointed context string */
> > +	switch (sectype) {
> > +	case CKPT_SECURITY_IPC:
> > +		ret = security_ipc_restore(v, l->string);
> 
> Nit: I know it's not strictly necessary, but adding an explicit
> type conversion here and in the other three seems cleaner

Hmm, it'll make some lines wrap making it harder to read, so it
was a tossup.  But ok I'll change it.

> > +		break;
> > +	case CKPT_SECURITY_MSG_MSG:
> > +		ret = security_msg_msg_restore(v, l->string);
> > +		break;
> > +	case CKPT_SECURITY_FILE:
> > +		ret = security_file_restore(v, l->string);
> > +		break;
> > +	case CKPT_SECURITY_CRED:
> > +		ret = security_cred_restore(ctx->file, v, l->string);
> > +		break;
> > +	default:
> > +		ret = -EINVAL;
> > +	}
> > +	if (ret)
> > +		ckpt_debug("sectype %d objref %d lsm's hook returned %d\n",
> > +			   sectype, secref, ret);
> > +	if (ret == -EOPNOTSUPP)
> > +		ret = 0;
> 
> If you silently ignore EOPNOTSUPP, how can a user tell if a restarted
> succeeded fully or by silently skipping the security part ?

Actually I agree, EOPNOTSUPP (or ENOSYS) with RESTART_KEEP_LSM should
just return failure.

> Should the user approve this behavior (e.g. RESTART_SECURITY_LAX...) ?
> 
> Also, I suggest the s/EOPNOTSUPP/ENOSYS/ all over the patch.

thanks,
-serge

  parent reply	other threads:[~2009-10-19 19:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19 14:43 [PATCH 1/4] add lsm name and lsm_info (policy header) to container info Serge E. Hallyn
     [not found] ` <20091019144315.GA30535-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-19 14:43   ` [PATCH 2/4] cr: add generic LSM c/r support (v6) Serge E. Hallyn
     [not found]     ` <20091019144341.GA30566-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-19 18:13       ` Oren Laadan
     [not found]         ` <4ADCAC5B.9080205-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-19 19:02           ` Serge E. Hallyn [this message]
     [not found]             ` <20091019190227.GA7201-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-21  1:03               ` Oren Laadan
     [not found]                 ` <4ADE5DEA.2000606-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-21  1:18                   ` Serge E. Hallyn
     [not found]                     ` <20091021011846.GA26728-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-21  1:21                       ` Oren Laadan
     [not found]                         ` <4ADE621E.2080603-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-21  5:01                           ` Serge E. Hallyn
2009-10-20  1:16           ` Serge E. Hallyn
2009-10-19 14:44   ` [PATCH user-cr] restart: accept the lsm_name field in header and add -k flag (v2) Serge E. Hallyn
2009-10-19 14:44   ` [PATCH 3/4] cr: add smack support to lsm c/r (v6) Serge E. Hallyn
2009-10-19 14:44   ` [PATCH 4/4] cr: add selinux support (v6) Serge E. Hallyn

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=20091019190227.GA7201@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox