mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Stephen Smalley <sds@epoch.ncsc.mil>
Cc: jmorris@redhat.com, linux-kernel@vger.kernel.org, selinux@tycho.nsa.gov
Subject: Re: [PATCH][SELINUX] Re-open descriptors closed on exec by SELinux to /dev/null
Date: Mon, 3 May 2004 14:41:30 -0700	[thread overview]
Message-ID: <20040503144130.42ba1fda.akpm@osdl.org> (raw)
In-Reply-To: <1083603014.7446.197.camel@moss-spartans.epoch.ncsc.mil>

Stephen Smalley <sds@epoch.ncsc.mil> wrote:
>
> +/* Create an open file that refers to the null device.
> +   Derived from the OpenWall LSM. */
> +struct file *open_devnull(void) 
> +{
> +	struct inode *inode;
> +	struct dentry *dentry;
> +	struct file *file = NULL;
> +	struct inode_security_struct *isec;
> +	dev_t dev;
> +
> +	inode = new_inode(current->fs->rootmnt->mnt_sb);
> +	if (!inode)
> +		goto out;
> +
> +	dentry = dget(d_alloc_root(inode));
> +	if (!dentry)
> +		goto out_iput;
> +
> +	file = get_empty_filp();
> +	if (!file)
> +		goto out_dput;
> +
> +	dev = MKDEV(MEM_MAJOR, 3); /* null device */
> +
> +	inode->i_uid = current->fsuid;
> +	inode->i_gid = current->fsgid;
> +	inode->i_blksize = PAGE_SIZE;
> +	inode->i_blocks = 0;
> +	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
> +	inode->i_state = I_DIRTY; /* so that mark_inode_dirty won't touch us */
> +
> +	isec = inode->i_security;
> +	isec->sid = SECINITSID_DEVNULL;
> +	isec->sclass = SECCLASS_CHR_FILE;
> +	isec->initialized = 1;
> +
> +	file->f_flags = O_RDWR;
> +	file->f_mode = FMODE_READ | FMODE_WRITE;
> +	file->f_dentry = dentry;
> +	file->f_vfsmnt = mntget(current->fs->rootmnt);
> +	file->f_pos = 0;
> +
> +	init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO, dev);
> +	if (inode->i_fop->open(inode, file))
> +		goto out_fput;
> +
> +out:
> +	return file;
> +out_fput:
> +	mntput(file->f_vfsmnt);
> +	put_filp(file);
> +out_dput:	
> +	dput(dentry);
> +out_iput:	
> +	iput(inode);
> +	file = NULL;
> +	goto out;
> +}

That seems to be a heck of a lot of code to get a file* which refers to
/dev/null.  I guess calling flip_open("/dev/null") is a bit grubby, but are
you sure there's no simpler way?


  reply	other threads:[~2004-05-03 21:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-03 16:50 Stephen Smalley
2004-05-03 21:41 ` Andrew Morton [this message]
2004-05-04 12:15   ` Stephen Smalley

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=20040503144130.42ba1fda.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sds@epoch.ncsc.mil \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®