[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Suggestion: binfmt_misc handling


  I was just poking around on my system and found a script I wrote back when
kernel 2.2 was released.  It was an experiment to see if I could easily handle
registration and deregistration of binary formats (with binfmt_misc) -- it
just occured to me that Debian might be interested in it, so here it is.

  Basically what you can do is create a directory called /etc/binfmt_misc and
put a bunch of files in it; each file should be a series of lines where each
line is a directive for the binfmt_misc registration file in /proc.  So the
incantation for Java is:
  (assuming that /usr/bin/javawrapper does something sensible), and for JPEG
(yes, this is a really dumb usage of binfmt_misc, but it's the only other
 magic number I could come up with offhand):


  Comments are also supported (by beginning a line with '#')

  Packages such as Wine, Kaffe, dosemu, and perhaps Frotz would drop a file
into this directory announcing their support of a binary format.  The files
wouldn't actually be interpreted unless this init.d script is installed; I
assume that someone is going to claim this is a security hazard, so I thought
I'd point that out :P

[ as I understand it, a security 'breach' could only occur with this system if a
 user had execute permissions but *not* read permissions on a file that wasn't
 of a normal executable format; in other words:
rwx--x--x /usr/bin/haha-you-cant-run-me.exe
  or if the user normally didn't have permissions to run the interpreter but had
 enough permissions to execute files of that type.  Both of these seem to me to
 be unusual cases, but who knows? :) ]

  The config file format could probably be made more sensible, but on the other
hand not many packages really need this and this format isn't *too* obscure..

  The init file is attached; it would be cool if a Real Developer[tm] could
stick it in a package.  I think this is a fairly useful bit of infrastructure.


  "Cogito, ergo sum."

  -- Descartes
# Register various binary types

test -e /proc/sys/fs/binfmt_misc || exit 0

register_format() {
while read -r FORMAT
  echo "$FORMAT" > /proc/sys/fs/binfmt_misc/register

case "$1" in
start)	echo -n "Registering binary formats: "
	for i in `find /etc/binfmt_misc/ -mindepth 1 -maxdepth 1 -not -name \*~`
	  echo -n `basename $i`
	  sed '/#.*/d' $i | register_format
	  echo -n ". "
	echo ""
stop)   echo -n "Disabling binary format recognition: "
	echo -1 > /proc/sys/fs/binfmt_misc/status
	echo "."
restart) $0 stop
	 $0 start
*)	echo "Usage: /etc/init.d/binfmt_misc start|stop|restart"; exit 1 
exit 0

Reply to: