linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cody P Schafer <cody@linux.vnet.ibm.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Cody P Schafer <cody@linux.vnet.ibm.com>
Subject: [PATCH] fs/binfmt_misc: avoid accidental exec disable via binfmt_misc loop
Date: Wed,  1 May 2013 15:49:20 -0700	[thread overview]
Message-ID: <1367448560-15514-1-git-send-email-cody@linux.vnet.ibm.com> (raw)

On my ubuntu system the update-binfmts command recently went berserk and
added a binfmt_misc for executing x86_64 elf files via a static qemu.
That static qemu is also an x86_64 elf (as are the majority of the
binaries on my x86_64 system). This prevented me from execing any new
programs and, due to the lack of an open root shell, made it impossible
for me to disable the offending binfmt.

[For anyone in a similar situation with update-binfmts going berserk, delete your
native arch's qemu from /var/lib/binfmts/ to allow binfmt-support to be installed]

This fix is a hack to disable binfmt_misc handlers when a loop occurs in
the hope of saving the system. Ideally, it would also attempt to
re-resolve the binfmt that was currently being resolved instead of
failing that one and allowing all that follows, but this behavior is
much better than the failure of everything that occurs right now.

Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
---
 fs/binfmt_misc.c | 5 +++++
 1 file changed, 5 insertions(+)

---

If this is considered too terrible, even adding a hack to sysrq to let me
recover the system (in the future) without a system reset would be appreciated.

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 751df5e..24e1ce6 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -197,6 +197,11 @@ static int load_misc_binary(struct linux_binprm *bprm)
 		goto _error;
 
 	retval = search_binary_handler(bprm);
+	if (retval == -ELOOP) {
+		pr_err("binfmt misc %s is involved in a loop, disabling.\n",
+				fmt->name);
+		clear_bit(Enabled, &fmt->flags);
+	}
 	if (retval < 0)
 		goto _error;
 
-- 
1.8.2.2


                 reply	other threads:[~2013-05-01 22:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1367448560-15514-1-git-send-email-cody@linux.vnet.ibm.com \
    --to=cody@linux.vnet.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).