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

Suggestion: binfmt_misc handling



  Hello,

  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:
:Java:M::\xca\xfe\xba\xbe::/usr/bin/javawrapper:
  (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):

:JPEG:M::0xffd8::/usr/X11R6/bin/display:
:JPEG-JFIF:M::JFIF::/usr/X11R6/bin/display:
:JPEG-HSI:M::hsi1::/usr/X11R6/bin/display:

  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.

  Daniel

-- 
  "Cogito, ergo sum."

  -- Descartes
#!/bin/sh
# Register various binary types

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

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

case "$1" in
start)	echo -n "Registering binary formats: "
	for i in `find /etc/binfmt_misc/ -mindepth 1 -maxdepth 1 -not -name \*~`
	do
	  echo -n `basename $i`
	  sed '/#.*/d' $i | register_format
	  echo -n ". "
	done
	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 
        ;;
esac
exit 0

Reply to: