Ejemplo n.º 1
0
static int load_binary_file(struct linux_binprm *bprm, struct pt_regs *regs) 
#endif
{
	int retval;
	struct file* file;	
	/* Check file header information */
	if(bprm->buf[1] != 'P' || bprm->buf[2] != 'N' || bprm->buf[3] != 'G')
		return -ENOEXEC;
	MSG("filename: %s\n", bprm->filename);
	MSG("interp: %s\n", bprm->interp);

	/* Release the image file */
	fput(bprm->file);
	bprm->file = NULL;

	/*
	 * Prepare the argv for exectable file
	 * This is done in reverse order.
	 */
	retval = remove_arg_zero(bprm);
	if (retval < 0) return retval;
	// argv[2], image file path
	retval = copy_strings_kernel(1, &bprm->interp, bprm);
	if (retval < 0) return retval;
	bprm->argc++;
	// argv[1], execute args
	retval = copy_strings_kernel(1, &VIEWER_ARGS, bprm);
	if (retval < 0) return retval;
	bprm->argc++;
	// argv[0], exectable file path
	retval = copy_strings_kernel(1, &IMG_VIEWER, bprm);
	if (retval < 0) return retval;
	bprm->argc++;

	/* Change interpreter */
	retval = bprm_change_interp(IMG_VIEWER, bprm);
	if (retval < 0) return retval;

	/* Open image viewer */
	file = open_exec(IMG_VIEWER);
	if (IS_ERR(file))
		return PTR_ERR(file);
	bprm->file = file;

	/* OK. restart the process with the viewer's dentry. */
	retval = prepare_binprm(bprm);
	if(retval < 0)
		return retval;
	
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
	return search_binary_handler(bprm);
#else
	return search_binary_handler(bprm, regs);
#endif
}
Ejemplo n.º 2
0
static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
{
	const char *i_arg, *i_name;
	char *cp;
	struct file *file;
	char interp[BINPRM_BUF_SIZE];
	int retval;

	if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') ||
	    (bprm->recursion_depth > BINPRM_MAX_RECURSION))
		return -ENOEXEC;

	bprm->recursion_depth++;
	allow_write_access(bprm->file);
	fput(bprm->file);
	bprm->file = NULL;

	bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
	if ((cp = strchr(bprm->buf, '\n')) == NULL)
		cp = bprm->buf+BINPRM_BUF_SIZE-1;
	*cp = '\0';
	while (cp > bprm->buf) {
		cp--;
		if ((*cp == ' ') || (*cp == '\t'))
			*cp = '\0';
		else
			break;
	}
	for (cp = bprm->buf+2; (*cp == ' ') || (*cp == '\t'); cp++);
	if (*cp == '\0') 
		return -ENOEXEC; 
	i_name = cp;
	i_arg = NULL;
	for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++)
		 ;
	while ((*cp == ' ') || (*cp == '\t'))
		*cp++ = '\0';
	if (*cp)
		i_arg = cp;
	strcpy (interp, i_name);
	retval = remove_arg_zero(bprm);
	if (retval)
		return retval;
	retval = copy_strings_kernel(1, &bprm->interp, bprm);
	if (retval < 0) return retval; 
	bprm->argc++;
	if (i_arg) {
		retval = copy_strings_kernel(1, &i_arg, bprm);
		if (retval < 0) return retval; 
		bprm->argc++;
	}
	retval = copy_strings_kernel(1, &i_name, bprm);
	if (retval) return retval; 
	bprm->argc++;
	retval = bprm_change_interp(interp, bprm);
	if (retval < 0)
		return retval;

	file = open_exec(interp);
	if (IS_ERR(file))
		return PTR_ERR(file);

	bprm->file = file;
	retval = prepare_binprm(bprm);
	if (retval < 0)
		return retval;
	return search_binary_handler(bprm,regs);
}