Skip to contentSkip to conversation

exec: refactor an invalid executable check to use isprint

PATCH In review Nir Lichtman 2 participants 3 messages Nov 15, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec: refactor an invalid executable check to use isprint

Remove private printable macro that is defined in exec.c and migrate to using the public isprint macro instead

---
 fs/exec.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/exec.c +2 -3
index 6c53920795c2..3394de5882af 100644
@@ -1723,7 +1723,6 @@ int remove_arg_zero(struct linux_binprm *bprm)
 }
 EXPORT_SYMBOL(remove_arg_zero);
 
-#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
 /*
  * cycle the list of binary formats handler, until one recognizes the image
  */
@@ -1761,8 +1760,8 @@ static int search_binary_handler(struct linux_binprm *bprm)
 	read_unlock(&binfmt_lock);
 
 	if (need_retry) {
-		if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
-		    printable(bprm->buf[2]) && printable(bprm->buf[3]))
+		if (isprint(bprm->buf[0]) && isprint(bprm->buf[1]) &&
+		    isprint(bprm->buf[2]) && isprint(bprm->buf[3]))
 			return retval;
 		if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0)
 			return retval;
Signature · 1 line
2.39.2
maintainer
#1 lore raw

fs/exec.c static int search_binary_handler(struct linux_binprm *bprm) · line 1764

Quoted 10 lines · Nir Lichtman

Remove private printable macro that is defined in exec.c and migrate to using the public isprint macro instead

fs/exec.c +2 -3
-#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
 
-		if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
-		    printable(bprm->buf[2]) && printable(bprm->buf[3]))
+		if (isprint(bprm->buf[0]) && isprint(bprm->buf[1]) &&
+		    isprint(bprm->buf[2]) && isprint(bprm->buf[3]))

RTFM(isprint). Or run a trivial loop and check what it does, for that matter.

isprint('\t') is false. So's isprint('\n').

#2 lore raw
Quoted 15 lines · Al Viro

fs/exec.c static int search_binary_handler(struct linux_binprm *bprm) · line 1764

Quoted 10 lines · Nir Lichtman

Remove private printable macro that is defined in exec.c and migrate to using the public isprint macro instead

fs/exec.c +2 -3
-#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
 
-		if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
-		    printable(bprm->buf[2]) && printable(bprm->buf[3]))
+		if (isprint(bprm->buf[0]) && isprint(bprm->buf[1]) &&
+		    isprint(bprm->buf[2]) && isprint(bprm->buf[3]))

RTFM(isprint). Or run a trivial loop and check what it does, for that matter.

Quoted 1 line

isprint('\t') is false. So's isprint('\n').

Right my bad I read _SP as _S by mistake, I'll send out another version with a fix considering the spaces