From 2f15be42ae2bfa486941b4a6ad733dac876b41af Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 4 Nov 2004 23:55:28 +0000 Subject: [PATCH] Check to see if the script has an ELF header, and if so, return ENOEXEC. --- sys/kern/exec_script.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c index 3974872ddef8..d076ae0a7342 100644 --- a/sys/kern/exec_script.c +++ b/sys/kern/exec_script.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp $ */ +/* $NetBSD: exec_script.c,v 1.38 2004/11/04 23:55:28 matt Exp $ */ /* * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.38 2004/11/04 23:55:28 matt Exp $"); #if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS) #define FDSCRIPTS /* Need this for safe set-id scripts. */ @@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp #include #include +#include /* * exec_script_makecmds(): Check if it's an executable shell script. @@ -107,6 +108,13 @@ exec_script_makecmds(struct proc *p, struct exec_package *epp) if (cp >= hdrstr + hdrlinelen) return ENOEXEC; + /* + * If the script has an ELF header, don't exec it. + */ + if (epp->ep_hdrvalid >= sizeof(ELFMAG)-1 && + memcmp(hdrstr, ELFMAG, sizeof(ELFMAG)-1) == 0) + return ENOEXEC; + shellname = NULL; shellarg = NULL; shellarglen = 0;