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: david@fromorbit.com, linux-fsdevel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: gfp flags for security_inode_alloc()?
Date: Mon, 09 Apr 2012 09:22:13 -0700	[thread overview]
Message-ID: <4F830CB5.2020806@schaufler-ca.com> (raw)
In-Reply-To: <201203290719.q2T7J5Z8043555@www262.sakura.ne.jp>

On 3/29/2012 12:19 AM, Tetsuo Handa wrote:
> Dave Chinner wrote:
>> Yes, because you have no idea what the calling context is except
>> for the fact that is from somewhere inside filesystem code and the
>> filesystem could be holding locks. Therefore, GFP_NOFS is really the
>> only really safe way to allocate memory here.
> I see. Thank you.
>
> I'm not sure, but can call trace happen where somewhere inside network
> filesystem or stackable filesystem code with locks held invokes operations that
> involves GFP_KENREL memory allocation outside that filesystem?
> ----------
> [PATCH] SMACK: Fix incorrect GFP_KERNEL usage.
>
> new_inode_smack() which can be called from smack_inode_alloc_security() needs
> to use GFP_NOFS like SELinux's inode_alloc_security() does, for
> security_inode_alloc() is called from inode_init_always() and
> inode_init_always() is called from xfs_inode_alloc() which is using GFP_NOFS.
>
> smack_inode_init_security() needs to use GFP_NOFS like
> selinux_inode_init_security() does, for initxattrs() callback function (e.g.
> btrfs_initxattrs()) which is called from security_inode_init_security() is
> using GFP_NOFS.
>
> smack_audit_rule_match() needs to use GFP_ATOMIC, for
> security_audit_rule_match() can be called from audit_filter_user_rules() and
> audit_filter_user_rules() is called from audit_filter_user() with RCU read lock
> held.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

Acked-by: Casey Schaufler <casey@schaufler-ca.com>

Applied after minor context adjustment to

git://gitorious.org/smack-next/kernel.git


>
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index cd667b4..697cf85 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -79,7 +79,7 @@ struct inode_smack *new_inode_smack(char *smack)
>  {
>  	struct inode_smack *isp;
>  
> -	isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
> +	isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS);
>  	if (isp == NULL)
>  		return NULL;
>  
> @@ -562,7 +562,7 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
>  	int may;
>  
>  	if (name) {
> -		*name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
> +		*name = kstrdup(XATTR_SMACK_SUFFIX, GFP_NOFS);
>  		if (*name == NULL)
>  			return -ENOMEM;
>  	}
> @@ -582,7 +582,7 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
>  		    smk_inode_transmutable(dir))
>  			isp = dsp;
>  
> -		*value = kstrdup(isp, GFP_KERNEL);
> +		*value = kstrdup(isp, GFP_NOFS);
>  		if (*value == NULL)
>  			return -ENOMEM;
>  	}
> @@ -3384,7 +3384,7 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
>  	char *rule = vrule;
>  
>  	if (!rule) {
> -		audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
> +		audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
>  			  "Smack: missing rule\n");
>  		return -ENOENT;
>  	}
>


      parent reply	other threads:[~2012-04-09 16:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28  4:22 gfp flags for security_inode_alloc()? Tetsuo Handa
2012-03-28 15:50 ` Casey Schaufler
2012-03-29  5:42 ` Dave Chinner
2012-03-29  7:19   ` Tetsuo Handa
2012-03-29 13:36     ` Casey Schaufler
2012-04-09 16:22     ` 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=4F830CB5.2020806@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=david@fromorbit.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /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.