lkml.org 
[lkml]   [1999]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: RFC: BSD system call revoke?
Hi Ted,

thank you for pointing out why revoke is not allowed to close the fd,
maybe you are right that only root/priviliged process should be allowed
to revoke.

> Finally, to whoever implements revoke: Note that it would be nice if the
> tty hangup code and the vhangup system call can be implemented in terms
> of the new revoke code. This would simplify the kernel a bit, since
> there's no reason why the tty hangup code needs to do and the revoke()
> system call needs to do shouldn't sure code paths.

Thank you for the pointer, i looked at the 'destroy-f_ops' loop in hangup,
so acually i think we can share some revoked-stubs with hangup so we don't
need to reinvent the wheel and we have a working revoke without mmap support
already there;

Leaving the mmap issue out for one moment, revoke should be this simple:

static ssize_t ret_null(struct file* filp, char* buf, size_t len, loff_t* off)
{
return 0;
}

static ssize_t ret_ioerr(struct file* f, const char* buf, size_t s, loff_t* o)
{
return -EIO;
}

static struct file_operations revoked_fops = {
NULL, /* default_llseek gives a good illusion... */
ret_null, /* read returns null bytes read */
ret_ioerr, /* write gives an IO Error */
NULL, /* readdir is not supported... */
revoked_poll, /* we will use hangup's poll stub */
revoked_ioctl, /* we will use hangup's ioctl stub */
NULL, /* no mmap anymore... */
NULL, /* open is NULL in hung_up_tty_fops */
NULL, /* flush is NULL in hung_up_tty_fops */
NULL, /* the fd will be closed later and NULL is ok */
NULL, /* fsync is also NULL in hung_up_tty_fops */
NULL, /* fasync is also NULL in hung_up_tty_fops */
NULL, /* check_media_change is not in hung_up_tty_fops */
NULL, /* revalidate is not in hung_up_tty_fops */
NULL /* lock is not in hung_up_tty_fops */
};

asmlinkage int sys_revoke(char * path)
{
int error;
struct dentry * dentry;
struct inode * inode;
struct file * filp;

lock_kernel();
dentry = namei(path);

error = PTR_ERR(dentry);
if (IS_ERR(dentry))
goto out;

if (!capable(CAP_DAC_OVERRIDE)) {
error = -EPERM;
goto dput_out;
}

inode = dentry->d_inode;

if (!(inode->i_mode & (S_IFBLK | S_IFCHR))) {
error = -EINVAL;
goto dput_out;
}

for (filp = inuse_filps; filp; filp = filp->f_next)
if (filp->f_dentry == dentry) {
down(&inode->i_sem);
if (filp->f_op && filp->f_op->release)
filp->f_op->release(inode, filp);
filp->f_op = &revoked_fops;
up(&inode->i_sem);
}
dput_out:
dput(dentry);
out:
unlock_kernel();
return error;
}

Should this be correct?

--

- Bernd





-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:52    [W:0.055 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site