public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Morris <jmorris@namei.org>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org,
	David Safford <safford@watson.ibm.com>,
	Serge Hallyn <serue@linux.vnet.ibm.com>,
	Reiner Sailer <sailer@us.ibm.com>, Mimi Zohar <zohar@us.ibm.com>
Subject: Re: [RFC][PATCH 4/5] integrity: Linux Integrity Module(LIM)
Date: Mon, 30 Jun 2008 20:43:20 +1000 (EST)	[thread overview]
Message-ID: <Xine.LNX.4.64.0806302023240.23266@us.intercode.com.au> (raw)
In-Reply-To: <1214583780.28077.17.camel@new-host.home>

On Fri, 27 Jun 2008, Mimi Zohar wrote:

> +const struct integrity_operations *integrity_ops = NULL;

This will be initialized to zero anyway.

> +
> +	if (!template_initialized++)
> +		INIT_LIST_HEAD(&integrity_templates);

Why not just intialize this at compile time with LIST_HEAD ?

> +	template_len = strlen(template_name);
> +	if (template_len > TEMPLATE_NAME_LEN_MAX)
> +		template_len = TEMPLATE_NAME_LEN_MAX;
> +	memcpy(entry->template_name, template_name, template_len);
> +	entry->template_name[template_len] = '\0';

Perhaps this would be simpler if you just bail with -EINVAL if the length 
is too great.  Then you can use strcpy and don't need to nul termiate the 
string for the caller.

> +	rc = integrity_find_template(template_name, &template_ops);
> +	if (rc == 0) {
> +		rc = template_ops->collect_measurement(data);
> +		rcu_read_unlock();
> +		return rc;
> +	}
> +	rcu_read_unlock();
> +	return -EINVAL;
> +}

If you give integrity_find_template() a standard form of returning 0 on 
success and -errno on failure, you can simplify the above quite a lot to 
have one unlock and one return.

> +	int rc;
> +
> +	rcu_read_lock();
> +	rc = integrity_find_template(template_name, &template_ops);
> +	if (rc == 0) {
> +		rc = template_ops->appraise_measurement(data);
> +		rcu_read_unlock();
> +		return rc;
> +	}
> +	rcu_read_unlock();
> +	return -EINVAL;
> +}

Ditto.

> +
> +EXPORT_SYMBOL_GPL(integrity_appraise_measurement);
> +
> +/**
> + * integrity_store_measurement - store template specific measurement
> + * @template_name: a pointer to a string containing the template name.
> + * @data: pointer to template specific data
> + *
> + * Store template specific integrity measurement.
> + */
> +void integrity_store_measurement(const char *template_name, void *data)
> +{
> +	const struct template_operations *template_ops;
> +	int rc;
> +
> +	rcu_read_lock();
> +	rc = integrity_find_template(template_name, &template_ops);
> +	if (rc == 0)
> +		template_ops->store_measurement(data);
> +	rcu_read_unlock();
> +	return;
> +}

So, the caller does not get an error if they supply an invalid template 
name?  That sounds like a bug which they need to know about.

> +/**
> + * integrity_must_measure - measure decision based on template policy
> + * @template_name: a pointer to a string containing the template name.
> + * @data: pointer to template specific data
> + *
> + * Returns 0 on success, an error code on failure.
> + */
> +int integrity_must_measure(const char *template_name, void *data)
> +{
> +	const struct template_operations *template_ops;
> +	int rc;
> +
> +	rcu_read_lock();
> +	rc = integrity_find_template(template_name, &template_ops);
> +	if (rc == 0) {
> +		rc = template_ops->must_measure(data);
> +		rcu_read_unlock();
> +		return rc;
> +	}
> +	rcu_read_unlock();
> +	return -EINVAL;
> +}

Do a single unlock and return.

> +/* Hook used to measure executable file integrity. */
> +int integrity_bprm_check(struct linux_binprm *bprm)
> +{
> +	int rc = 0;
> +
> +	if (integrity_ops && integrity_ops->bprm_check_integrity)
> +		rc = integrity_ops->bprm_check_integrity(bprm);
> +	return rc;
> +}

Have you considered using a set of dummy ops similar to LSM, so that 
integrity_ops->whatever will always point to something and can be 
unconditionally called?  (see security_fixup_ops()).



- James
-- 
James Morris
<jmorris@namei.org>

  reply	other threads:[~2008-06-30 10:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080627131946.225566613@linux.vnet.ibm.com>
2008-06-27 16:22 ` [RFC][PATCH 1/5] integrity: TPM cleanup Mimi Zohar
2008-06-30  9:13   ` James Morris
2008-06-27 16:22 ` [RFC][PATCH 2/5] integrity: TPM internel kernel interface Mimi Zohar
2008-06-30 10:04   ` James Morris
2008-06-27 16:22 ` [RFC][PATCH 3/5] integrity: special fs magic Mimi Zohar
2008-06-30 10:06   ` James Morris
2008-06-27 16:23 ` [RFC][PATCH 4/5] integrity: Linux Integrity Module(LIM) Mimi Zohar
2008-06-30 10:43   ` James Morris [this message]
2008-06-30 21:21     ` Mimi Zohar
2008-06-27 16:23 ` [RFC][PATCH 5/5] integrity: IMA as an integrity service provider Mimi Zohar
2008-06-27 16:23 ` LTP IMA patch Mimi Zohar
2008-05-23 15:05 [RFC][PATCH 4/5]integrity: Linux Integrity Module(LIM) Mimi Zohar
2008-05-23 23:30 ` Randy Dunlap
2008-05-27 14:34   ` Mimi Zohar
2008-05-28  7:46 ` Andrew Morton
2008-05-29  2:46   ` Mimi Zohar
2008-05-29  4:46     ` James Morris

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=Xine.LNX.4.64.0806302023240.23266@us.intercode.com.au \
    --to=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=safford@watson.ibm.com \
    --cc=sailer@us.ibm.com \
    --cc=serue@linux.vnet.ibm.com \
    --cc=zohar@linux.vnet.ibm.com \
    --cc=zohar@us.ibm.com \
    /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