19 #include <linux/module.h>
21 #include <linux/sched.h>
22 #include <linux/magic.h>
23 #include <linux/binfmts.h>
24 #include <linux/slab.h>
25 #include <linux/ctype.h>
33 #include <asm/uaccess.h>
43 #define MISC_FMT_PRESERVE_ARGV0 (1<<31)
44 #define MISC_FMT_OPEN_BINARY (1<<30)
45 #define MISC_FMT_CREDENTIALS (1<<29)
90 for (j = 0; j < e->
size; j++)
94 for (j = 0; j < e->
size; j++)
95 if ((*s++ ^ e->
magic[j]))
112 const char *iname_addr = iname;
126 fmt = check_file(bprm);
155 allow_write_access(bprm->
file);
163 allow_write_access(bprm->
file);
182 retval = PTR_ERR (interp_file);
183 if (IS_ERR (interp_file))
186 bprm->
file = interp_file;
224 static char *scanarg(
char *s,
char del)
228 while ((c = *s++) != del) {
229 if (c ==
'\\' && *s ==
'x') {
240 static int unquote(
char *
from)
244 while ((c = *s++) !=
'\0') {
245 if (c ==
'\\' && *s ==
'x') {
248 *p = (c - (
isdigit(c) ?
'0' :
'A' - 10)) << 4;
250 *p++ |= c - (
isdigit(c) ?
'0' :
'A' - 10);
258 static char * check_special_flags (
char * sfs,
Node * e)
302 if ((count < 11) || (count > 256))
306 memsize =
sizeof(
Node) + count + 8;
311 p = buf = (
char *)e +
sizeof(
Node);
319 memset(buf+count, del, 8);
334 default:
goto Einval;
391 p = check_special_flags (p, e);
395 if (p != buf + count)
414 static int parse_command(
const char __user *buffer,
size_t count)
424 if (s[count-1] ==
'\n')
426 if (count == 1 && s[0] ==
'0')
428 if (count == 1 && s[0] ==
'1')
430 if (count == 2 && s[0] ==
'-' && s[1] ==
'1')
437 static void entry_status(
Node *e,
char *
page)
440 char *
status =
"disabled";
441 const char *
flags =
"flags: ";
476 for (i = 0; i < e->
size; i++) {
483 for (i = 0; i < e->
size; i++) {
506 static void bm_evict_inode(
struct inode *inode)
512 static void kill_node(
Node *e)
519 list_del_init(&e->
list);
535 bm_entry_read(
struct file *
file,
char __user * buf,
size_t nbytes, loff_t *ppos)
537 Node *e = file->
f_path.dentry->d_inode->i_private;
544 entry_status(e, page);
552 static ssize_t bm_entry_write(
struct file *file,
const char __user *buffer,
553 size_t count, loff_t *ppos)
556 Node *e = file->
f_path.dentry->d_inode->i_private;
557 int res = parse_command(buffer, count);
564 case 3: root = dget(file->
f_path.dentry->d_sb->s_root);
578 .read = bm_entry_read,
579 .write = bm_entry_write,
585 static ssize_t bm_register_write(
struct file *file,
const char __user *buffer,
586 size_t count, loff_t *ppos)
590 struct dentry *root, *dentry;
594 e = create_entry(buffer, count);
602 err = PTR_ERR(dentry);
610 inode = bm_get_inode(sb,
S_IFREG | 0644);
625 inode->
i_fop = &bm_entry_operations;
647 .write = bm_register_write,
654 bm_status_read(
struct file *file,
char __user *buf,
size_t nbytes, loff_t *ppos)
656 char *s =
enabled ?
"enabled\n" :
"disabled\n";
661 static ssize_t bm_status_write(
struct file * file,
const char __user * buffer,
662 size_t count, loff_t *ppos)
664 int res = parse_command(buffer, count);
670 case 3: root = dget(file->
f_path.dentry->d_sb->s_root);
684 .read = bm_status_read,
685 .write = bm_status_write,
693 .evict_inode = bm_evict_inode,
696 static int bm_fill_super(
struct super_block * sb,
void *
data,
int silent)
700 [3] = {
"register", &bm_register_operations,
S_IWUSR},
710 int flags,
const char *dev_name,
void *data)
712 return mount_single(fs_type, flags, data, bm_fill_super);
717 .load_binary = load_misc_binary,
722 .name =
"binfmt_misc",
727 static int __init init_misc_binfmt(
void)
731 insert_binfmt(&misc_format);
735 static void __exit exit_misc_binfmt(
void)