Skip to contentSkip to conversation

execve: block Emacs binaries

PATCH In review Mateusz Guzik 6 participants 10 messages Apr 1 – Apr 7

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

PATCH 1/1 execve: block Emacs binaries

No justification needed.

A new errno is introduced to indicate what happened.

---
 fs/exec.c                        | 16 ++++++++++++++++
 include/uapi/asm-generic/errno.h |  2 ++
 2 files changed, 18 insertions(+)
fs/exec.c +16 -0
index 9ea3a775d51e..2e954b31e3a2 100644
@@ -1725,6 +1725,22 @@ static int bprm_execve(struct linux_binprm *bprm)
 {
 	int retval;
 
+	/*
+	 * Trivial attempt at blocking execution of Emacs.
+	 *
+	 * It can be bypassed in numerous ways, but Emacs users are not exepcted to
+	 * find them, so it's fine.
+	 *
+	 * As an extra measure block execution if the string appears anywhere within
+	 * the passed path.
+	 */
+	if (strstr(bprm->filename, "emacs")) {
+		/*
+		 * Disgusting!
+		 */
+		return -EMACS;
+	}
+
 	retval = prepare_bprm_creds(bprm);
 	if (retval)
 		return retval;
include/uapi/asm-generic/errno.h +2 -0
index 92e7ae493ee3..1a8fda40cd8a 100644
@@ -122,4 +122,6 @@
 
 #define EHWPOISON	133	/* Memory page has hardware error */
 
+#define EMACS		134	/* Editor too big */
+
 #endif
Signature · 1 line
2.48.1
#1 lore raw
Quoted 24 lines · Mateusz Guzik

No justification needed.

A new errno is introduced to indicate what happened.

---
 fs/exec.c                        | 16 ++++++++++++++++
 include/uapi/asm-generic/errno.h |  2 ++
 2 files changed, 18 insertions(+)
fs/exec.c +6 -0
index 9ea3a775d51e..2e954b31e3a2 100644
@@ -1725,6 +1725,22 @@ static int bprm_execve(struct linux_binprm *bprm)
 {
 	int retval;
 
+	/*
+	 * Trivial attempt at blocking execution of Emacs.
+	 *
+	 * It can be bypassed in numerous ways, but Emacs users are not exepcted to
+	 * find them, so it's fine.
+	 *

fs/exec.c static int bprm_execve(struct linux_binprm *bprm) · line 1743

Quoted 10 lines
fs/exec.c +10 -0
+	 * As an extra measure block execution if the string appears anywhere within
+	 * the passed path.
+	 */
+	if (strstr(bprm->filename, "emacs")) {
+		/*
+		 * Disgusting!
+		 */
+		return -EMACS;
+	}
+

Can you block vim too? We only use ed(1) and GNU nano in this house.

Signature · 1 line
Pedro
#2 lore raw
Quoted 2 lines · Pedro Falcato

Can you block vim too? We only use ed(1) and GNU nano in this house.

I heard nano is a company-issued editor at Suse.

If I wanted to mess with Red Hat I would block mcedit.

#3 lore raw
Quoted 8 lines · On Wed, 1 Apr 2026 21:24:54 +0200 Mateusz Guzik <[email protected]> wrote:
Quoted 2 lines · Pedro Falcato

Can you block vim too? We only use ed(1) and GNU nano in this house.

I heard nano is a company-issued editor at Suse.

If I wanted to mess with Red Hat I would block mcedit.

You are all wimps.

Try editing files in a small 'miniroot' for an embedded system. If you are really lucky you've got a shell that supports ## and %%.

David

#4 lore raw

[PATCH 2/1] execve: only smart people should use vim

In reply to Mateusz Guzik

From: Steven Rostedt <[email protected]>

To keep people from getting stuck in vim and not knowing how to exit it. Make running vim a bit more complex.

They can go back and use emacs, of course that will fail too, but then they have something to work on.

---
 fs/exec.c                        | 11 +++++++++++
 include/uapi/asm-generic/errno.h |  1 +
 2 files changed, 12 insertions(+)
fs/exec.c +11 -0
index 2e954b31e3a2..ecb425388008 100644
@@ -1741,6 +1741,17 @@ static int bprm_execve(struct linux_binprm *bprm)
 		return -EMACS;
 	}
 
+	/*
+	 * Only really smart people should use vim. If they can't figure out
+	 * how to circumvent this, then they have no right using it!
+	 */
+	if (strstr(bprm->filename, "vim")) {
+		/*
+		 * Learn to code!
+		 */
+		return -NOTEMACS;
+	}
+
 	retval = prepare_bprm_creds(bprm);
 	if (retval)
 		return retval;
include/uapi/asm-generic/errno.h +1 -0
index 1a8fda40cd8a..4cc4ae653cec 100644
@@ -123,5 +123,6 @@
 #define EHWPOISON	133	/* Memory page has hardware error */
 
 #define EMACS		134	/* Editor too big */
+#define NOTEMACS	135	/* Editor used by smart people */
 
 #endif
Signature · 1 line
2.51.0
author Reviewed-by
#5 lore raw

Re: [PATCH 2/1] execve: only smart people should use vim

Quoted 24 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

To keep people from getting stuck in vim and not knowing how to exit it. Make running vim a bit more complex.

They can go back and use emacs, of course that will fail too, but then they have something to work on.

---
 fs/exec.c                        | 11 +++++++++++
 include/uapi/asm-generic/errno.h |  1 +
 2 files changed, 12 insertions(+)
fs/exec.c +1 -0
index 2e954b31e3a2..ecb425388008 100644
@@ -1741,6 +1741,17 @@ static int bprm_execve(struct linux_binprm *bprm)
                return -EMACS;
        }
 
+       /*

fs/exec.c static int bprm_execve(struct linux_binprm *bprm) · line 1754

Quoted 10 lines
fs/exec.c +10 -0
+        * Only really smart people should use vim. If they can't figure out
+        * how to circumvent this, then they have no right using it!
+        */
+       if (strstr(bprm->filename, "vim")) {
+               /*
+                * Learn to code!
+                */
+               return -NOTEMACS;
+       }
+

I would consider extending this to nvim, otherwise looks good.

Quoted 17 lines
fs/exec.c +0 -0
        retval = prepare_bprm_creds(bprm);
        if (retval)
                return retval;
include/uapi/asm-generic/errno.h +1 -1
index 1a8fda40cd8a..4cc4ae653cec 100644
@@ -123,5 +123,6 @@
 #define EHWPOISON      133     /* Memory page has hardware error */
 
 #define EMACS          134     /* Editor too big */
+#define NOTEMACS       135     /* Editor used by smart people */
 
 #endif
--

2.51.0

#6 lore raw

Re: [PATCH 2/1] execve: only smart people should use vim

Quoted 25 lines · Mateusz Guzik
Quoted 23 lines · Steven Rostedt

From: Steven Rostedt <[email protected]>

To keep people from getting stuck in vim and not knowing how to exit it. Make running vim a bit more complex.

They can go back and use emacs, of course that will fail too, but then they have something to work on.

---
 fs/exec.c                        | 11 +++++++++++
 include/uapi/asm-generic/errno.h |  1 +
 2 files changed, 12 insertions(+)
fs/exec.c +0 -0
index 2e954b31e3a2..ecb425388008 100644
@@ -1741,6 +1741,17 @@ static int bprm_execve(struct linux_binprm *bprm)
                return -EMACS;
        }
 
Quoted 13 lines

fs/exec.c static int bprm_execve(struct linux_binprm *bprm) · line 1754

Quoted 11 lines
fs/exec.c +11 -0
+       /*
+        * Only really smart people should use vim. If they can't figure out
+        * how to circumvent this, then they have no right using it!
+        */
+       if (strstr(bprm->filename, "vim")) {
+               /*
+                * Learn to code!
+                */
+               return -NOTEMACS;
+       }
+

I would consider extending this to nvim, otherwise looks good.

that's of course already covered, my bad!

Quoted 20 lines
Quoted 17 lines
fs/exec.c +0 -0
        retval = prepare_bprm_creds(bprm);
        if (retval)
                return retval;
include/uapi/asm-generic/errno.h +1 -1
index 1a8fda40cd8a..4cc4ae653cec 100644
@@ -123,5 +123,6 @@
 #define EHWPOISON      133     /* Memory page has hardware error */
 
 #define EMACS          134     /* Editor too big */
+#define NOTEMACS       135     /* Editor used by smart people */
 
 #endif
--

2.51.0

#7 lore raw
In reply to Mateusz Guzik
Quoted 23 lines · Mateusz Guzik

No justification needed.

A new errno is introduced to indicate what happened.

---
 fs/exec.c                        | 16 ++++++++++++++++
 include/uapi/asm-generic/errno.h |  2 ++
 2 files changed, 18 insertions(+)
fs/exec.c +5 -0
index 9ea3a775d51e..2e954b31e3a2 100644
@@ -1725,6 +1725,22 @@ static int bprm_execve(struct linux_binprm *bprm)
 {
 	int retval;
 
+	/*
+	 * Trivial attempt at blocking execution of Emacs.
+	 *
+	 * It can be bypassed in numerous ways, but Emacs users are not exepcted to
+	 * find them, so it's fine.

fs/exec.c static int bprm_execve(struct linux_binprm *bprm) · line 1742

Quoted 10 lines
fs/exec.c +10 -0
+	 *
+	 * As an extra measure block execution if the string appears anywhere within
+	 * the passed path.
+	 */
+	if (strstr(bprm->filename, "emacs")) {
+		/*
+		 * Disgusting!
+		 */
+		return -EMACS;
+	}

Won't this break some existing text editing workflows? To ensure a seamless transition I'd suggest also embedding a copy of a proper text editor into the kernel image, and making the kernel automatically replace the emacs binary with it.

- Eric

#8 lore raw
In reply to Mateusz Guzik
kernel test robot noticed the following build errors:

Hi Mateusz,

kernel test robot noticed the following build errors:

[auto build test ERROR on kees/for-next/execve]
[also build test ERROR on arnd-asm-generic/master linus/master v7.0-rc6 next-20260403] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/execve-block-Emacs-binaries/20260405-070808
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/execve
patch link:    https://lore.kernel.org/r/20260401131226.4011156-1-mjguzik%40gmail.com
patch subject: [PATCH] execve: block Emacs binaries
config: parisc-allnoconfig (https://download.01.org/0day-ci/archive/20260405/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260405/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

fs/exec.c: In function 'bprm_execve':

>> fs/exec.c:1741:25: error: 'EMACS' undeclared (first use in this function)
    1741 |                 return -EMACS;
         |                         ^~~~~

fs/exec.c:1741:25: note: each undeclared identifier is reported only once for each function it appears in

vim +/EMACS +1741 fs/exec.c

1723
1724 static int bprm_execve(struct linux_binprm *bprm)
1725 {
1726 int retval;
1727
1728 /*
1729 * Trivial attempt at blocking execution of Emacs.
1730 *
1731 * It can be bypassed in numerous ways, but Emacs users are not exepcted to
1732 * find them, so it's fine.
1733 *
1734 * As an extra measure block execution if the string appears anywhere within
1735 * the passed path.
1736 */
1737 if (strstr(bprm->filename, "emacs")) {
1738 /*
1739 * Disgusting!
1740 */

> 1741			return -EMACS;

1742 }
1743
1744 retval = prepare_bprm_creds(bprm);
1745 if (retval)
1746 return retval;
1747
1748 /*
1749 * Check for unsafe execution states before exec_binprm(), which
1750 * will call back into begin_new_exec(), into bprm_creds_from_file(),
1751 * where setuid-ness is evaluated.
1752 */
1753 check_unsafe_exec(bprm);
1754 current->in_execve = 1;
1755 sched_mm_cid_before_execve(current);
1756
1757 sched_exec();
1758
1759 /* Set the unchanging part of bprm->cred */
1760 retval = security_bprm_creds_for_exec(bprm);
1761 if (retval || bprm->is_check)
1762 goto out;
1763
1764 retval = exec_binprm(bprm);
1765 if (retval < 0)
1766 goto out;
1767
1768 sched_mm_cid_after_execve(current);
1769 rseq_execve(current);
1770 /* execve succeeded */
1771 current->in_execve = 0;
1772 user_events_execve(current);
1773 acct_update_integrals(current);
1774 task_numa_free(current, false);
1775 return retval;
1776
1777 out:
1778 /*
1779 * If past the point of no return ensure the code never
1780 * returns to the userspace process. Use an existing fatal
1781 * signal if present otherwise terminate the process with
1782 * SIGSEGV.
1783 */
1784 if (bprm->point_of_no_return && !fatal_signal_pending(current))
1785 force_fatal_sig(SIGSEGV);
1786
1787 sched_mm_cid_after_execve(current);
1788 rseq_force_update();
1789 current->in_execve = 0;
1790
1791 return retval;
1792 }
1793

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw
In reply to Mateusz Guzik
kernel test robot noticed the following build errors:

Hi Mateusz,

kernel test robot noticed the following build errors:

[auto build test ERROR on kees/for-next/execve]
[also build test ERROR on arnd-asm-generic/master linus/master v7.0-rc6 next-20260403] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mateusz-Guzik/execve-block-Emacs-binaries/20260405-070808
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/execve
patch link:    https://lore.kernel.org/r/20260401131226.4011156-1-mjguzik%40gmail.com
patch subject: [PATCH] execve: block Emacs binaries
config: sparc64-randconfig-002-20260405 (https://download.01.org/0day-ci/archive/20260405/[email protected]/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project c80443cd37b2e2788cba67ffa180a6331e5f0791)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260405/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> fs/exec.c:1741:11: error: use of undeclared identifier 'EMACS'
    1741 |                 return -EMACS;
         |                         ^~~~~

1 error generated.

vim +/EMACS +1741 fs/exec.c

1723
1724 static int bprm_execve(struct linux_binprm *bprm)
1725 {
1726 int retval;
1727
1728 /*
1729 * Trivial attempt at blocking execution of Emacs.
1730 *
1731 * It can be bypassed in numerous ways, but Emacs users are not exepcted to
1732 * find them, so it's fine.
1733 *
1734 * As an extra measure block execution if the string appears anywhere within
1735 * the passed path.
1736 */
1737 if (strstr(bprm->filename, "emacs")) {
1738 /*
1739 * Disgusting!
1740 */

> 1741			return -EMACS;

1742 }
1743
1744 retval = prepare_bprm_creds(bprm);
1745 if (retval)
1746 return retval;
1747
1748 /*
1749 * Check for unsafe execution states before exec_binprm(), which
1750 * will call back into begin_new_exec(), into bprm_creds_from_file(),
1751 * where setuid-ness is evaluated.
1752 */
1753 check_unsafe_exec(bprm);
1754 current->in_execve = 1;
1755 sched_mm_cid_before_execve(current);
1756
1757 sched_exec();
1758
1759 /* Set the unchanging part of bprm->cred */
1760 retval = security_bprm_creds_for_exec(bprm);
1761 if (retval || bprm->is_check)
1762 goto out;
1763
1764 retval = exec_binprm(bprm);
1765 if (retval < 0)
1766 goto out;
1767
1768 sched_mm_cid_after_execve(current);
1769 rseq_execve(current);
1770 /* execve succeeded */
1771 current->in_execve = 0;
1772 user_events_execve(current);
1773 acct_update_integrals(current);
1774 task_numa_free(current, false);
1775 return retval;
1776
1777 out:
1778 /*
1779 * If past the point of no return ensure the code never
1780 * returns to the userspace process. Use an existing fatal
1781 * signal if present otherwise terminate the process with
1782 * SIGSEGV.
1783 */
1784 if (bprm->point_of_no_return && !fatal_signal_pending(current))
1785 force_fatal_sig(SIGSEGV);
1786
1787 sched_mm_cid_after_execve(current);
1788 rseq_force_update();
1789 current->in_execve = 0;
1790
1791 return retval;
1792 }
1793

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki