home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Opcode - Disable named opcodes when compiling perl code</TITLE>
- <LINK REL="stylesheet" HREF="../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Opcode - Disable named opcodes when compiling perl code</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#note">NOTE</A></LI>
- <LI><A HREF="#warning">WARNING</A></LI>
- <LI><A HREF="#operator names and operator lists">Operator Names and Operator Lists</A></LI>
- <LI><A HREF="#opcode functions">Opcode Functions</A></LI>
- <LI><A HREF="#manipulating opsets">Manipulating Opsets</A></LI>
- <LI><A HREF="#to do (maybe)">TO DO (maybe)</A></LI>
- <LI><A HREF="#predefined opcode tags">Predefined Opcode Tags</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#authors">AUTHORS</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Opcode - Disable named opcodes when compiling perl code</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use Opcode;</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>Perl code is always compiled into an internal format before execution.</P>
- <P>Evaluating perl code (e.g. via ``eval'' or ``do 'file''') causes
- the code to be compiled into an internal format and then,
- provided there was no error in the compilation, executed.
- The internal format is based on many distinct <EM>opcodes</EM>.</P>
- <P>By default no opmask is in effect and any code can be compiled.</P>
- <P>The Opcode module allow you to define an <EM>operator mask</EM> to be in
- effect when perl <EM>next</EM> compiles any code. Attempting to compile code
- which contains a masked opcode will cause the compilation to fail
- with an error. The code will not be executed.</P>
- <P>
- <HR>
- <H1><A NAME="note">NOTE</A></H1>
- <P>The Opcode module is not usually used directly. See the ops pragma and
- Safe modules for more typical uses.</P>
- <P>
- <HR>
- <H1><A NAME="warning">WARNING</A></H1>
- <P>The authors make <STRONG>no warranty</STRONG>, implied or otherwise, about the
- suitability of this software for safety or security purposes.</P>
- <P>The authors shall not in any case be liable for special, incidental,
- consequential, indirect or other similar damages arising from the use
- of this software.</P>
- <P>Your mileage will vary. If in any doubt <STRONG>do not use it</STRONG>.</P>
- <P>
- <HR>
- <H1><A NAME="operator names and operator lists">Operator Names and Operator Lists</A></H1>
- <P>The canonical list of operator names is the contents of the array
- PL_op_name defined and initialised in file <EM>opcode.h</EM> of the Perl
- source distribution (and installed into the perl library).</P>
- <P>Each operator has both a terse name (its opname) and a more verbose or
- recognisable descriptive name. The opdesc function can be used to
- return a list of descriptions for a list of operators.</P>
- <P>Many of the functions and methods listed below take a list of
- operators as parameters. Most operator lists can be made up of several
- types of element. Each element can be one of</P>
- <DL>
- <DT><STRONG><A NAME="item_name">an operator name (opname)</A></STRONG><BR>
- <DD>
- Operator names are typically small lowercase words like enterloop,
- leaveloop, last, next, redo etc. Sometimes they are rather cryptic
- like gv2cv, i_ncmp and ftsvtx.
- <P></P>
- <DT><STRONG>an operator tag name (optag)</STRONG><BR>
- <DD>
- Operator tags can be used to refer to groups (or sets) of operators.
- Tag names always begin with a colon. The Opcode module defines several
- optags and the user can define others using the define_optag function.
- <P></P>
- <DT><STRONG><A NAME="item_a_negated_opname_or_optag">a negated opname or optag</A></STRONG><BR>
- <DD>
- An opname or optag can be prefixed with an exclamation mark, e.g., !mkdir.
- Negating an opname or optag means remove the corresponding ops from the
- accumulated set of ops at that point.
- <P></P>
- <DT><STRONG><A NAME="item_set">an operator set (opset)</A></STRONG><BR>
- <DD>
- An <EM>opset</EM> as a binary string of approximately 43 bytes which holds a
- set or zero or more operators.
- <P>The opset and opset_to_ops functions can be used to convert from
- a list of operators to an opset and <EM>vice versa</EM>.</P>
- <P>Wherever a list of operators can be given you can use one or more opsets.
- See also Manipulating Opsets below.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="opcode functions">Opcode Functions</A></H1>
- <P>The Opcode package contains functions for manipulating operator names
- tags and sets. All are available for export by the package.</P>
- <DL>
- <DT><STRONG><A NAME="item_opcodes">opcodes</A></STRONG><BR>
- <DD>
- In a scalar context opcodes returns the number of opcodes in this
- version of perl (around 340 for perl5.002).
- <P>In a list context it returns a list of all the operator names.
- (Not yet implemented, use @names = <A HREF="#item_opset_to_ops"><CODE>opset_to_ops(full_opset).)</CODE></A></P>
- <P></P>
- <DT><STRONG><A NAME="item_opset">opset (OP, ...)</A></STRONG><BR>
- <DD>
- Returns an opset containing the listed operators.
- <P></P>
- <DT><STRONG><A NAME="item_opset_to_ops">opset_to_ops (OPSET)</A></STRONG><BR>
- <DD>
- Returns a list of operator names corresponding to those operators in
- the set.
- <P></P>
- <DT><STRONG><A NAME="item_opset_to_hex">opset_to_hex (OPSET)</A></STRONG><BR>
- <DD>
- Returns a string representation of an opset. Can be handy for debugging.
- <P></P>
- <DT><STRONG><A NAME="item_full_opset">full_opset</A></STRONG><BR>
- <DD>
- Returns an opset which includes all operators.
- <P></P>
- <DT><STRONG><A NAME="item_empty_opset">empty_opset</A></STRONG><BR>
- <DD>
- Returns an opset which contains no operators.
- <P></P>
- <DT><STRONG><A NAME="item_invert_opset">invert_opset (OPSET)</A></STRONG><BR>
- <DD>
- Returns an opset which is the inverse set of the one supplied.
- <P></P>
- <DT><STRONG><A NAME="item_verify_opset">verify_opset (OPSET, ...)</A></STRONG><BR>
- <DD>
- Returns true if the supplied opset looks like a valid opset (is the
- right length etc) otherwise it returns false. If an optional second
- parameter is true then verify_opset will croak on an invalid opset
- instead of returning false.
- <P>Most of the other Opcode functions call verify_opset automatically
- and will croak if given an invalid opset.</P>
- <P></P>
- <DT><STRONG><A NAME="item_define_optag">define_optag (OPTAG, OPSET)</A></STRONG><BR>
- <DD>
- Define OPTAG as a symbolic name for OPSET. Optag names always start
- with a colon <CODE>:</CODE>.
- <P>The optag name used must not be defined already (define_optag will
- croak if it is already defined). Optag names are global to the perl
- process and optag definitions cannot be altered or deleted once
- defined.</P>
- <P>It is strongly recommended that applications using Opcode should use a
- leading capital letter on their tag names since lowercase names are
- reserved for use by the Opcode module. If using Opcode within a module
- you should prefix your tags names with the name of your module to
- ensure uniqueness and thus avoid clashes with other modules.</P>
- <P></P>
- <DT><STRONG><A NAME="item_opmask_add">opmask_add (OPSET)</A></STRONG><BR>
- <DD>
- Adds the supplied opset to the current opmask. Note that there is
- currently <EM>no</EM> mechanism for unmasking ops once they have been masked.
- This is intentional.
- <P></P>
- <DT><STRONG><A NAME="item_opmask">opmask</A></STRONG><BR>
- <DD>
- Returns an opset corresponding to the current opmask.
- <P></P>
- <DT><STRONG><A NAME="item_opdesc">opdesc (OP, ...)</A></STRONG><BR>
- <DD>
- This takes a list of operator names and returns the corresponding list
- of operator descriptions.
- <P></P>
- <DT><STRONG><A NAME="item_opdump">opdump (PAT)</A></STRONG><BR>
- <DD>
- Dumps to STDOUT a two column list of op names and op descriptions.
- If an optional pattern is given then only lines which match the
- (case insensitive) pattern will be output.
- <P>It's designed to be used as a handy command line utility:</P>
- <PRE>
- perl -MOpcode=opdump -e opdump
- perl -MOpcode=opdump -e 'opdump Eval'</PRE>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="manipulating opsets">Manipulating Opsets</A></H1>
- <P>Opsets may be manipulated using the perl bit vector operators & (and), | (or),
- ^ (xor) and ~ (negate/invert).</P>
- <P>However you should never rely on the numerical position of any opcode
- within the opset. In other words both sides of a bit vector operator
- should be opsets returned from Opcode functions.</P>
- <P>Also, since the number of opcodes in your current version of perl might
- not be an exact multiple of eight, there may be unused bits in the last
- byte of an upset. This should not cause any problems (Opcode functions
- ignore those extra bits) but it does mean that using the ~ operator
- will typically not produce the same 'physical' opset 'string' as the
- invert_opset function.</P>
- <P>
- <HR>
- <H1><A NAME="to do (maybe)">TO DO (maybe)</A></H1>
- <PRE>
- $bool = opset_eq($opset1, $opset2) true if opsets are logically eqiv</PRE>
- <PRE>
- $yes = opset_can($opset, @ops) true if $opset has all @ops set</PRE>
- <PRE>
- @diff = opset_diff($opset1, $opset2) => ('foo', '!bar', ...)</PRE>
- <P>
- <HR>
- <H1><A NAME="predefined opcode tags">Predefined Opcode Tags</A></H1>
- <DL>
- <DT><STRONG><A NAME="item_%3Abase_core">:base_core</A></STRONG><BR>
- <DD>
- <PRE>
- null stub scalar pushmark wantarray const defined undef</PRE>
- <PRE>
- rv2sv sassign</PRE>
- <PRE>
- rv2av aassign aelem aelemfast aslice av2arylen</PRE>
- <PRE>
- rv2hv helem hslice each values keys exists delete</PRE>
- <PRE>
- preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec
- int hex oct abs pow multiply i_multiply divide i_divide
- modulo i_modulo add i_add subtract i_subtract</PRE>
- <PRE>
- left_shift right_shift bit_and bit_xor bit_or negate i_negate
- not complement</PRE>
- <PRE>
- lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp
- slt sgt sle sge seq sne scmp</PRE>
- <PRE>
- substr vec stringify study pos length index rindex ord chr</PRE>
- <PRE>
- ucfirst lcfirst uc lc quotemeta trans chop schop chomp schomp</PRE>
- <PRE>
- match split qr</PRE>
- <PRE>
- list lslice splice push pop shift unshift reverse</PRE>
- <PRE>
- cond_expr flip flop andassign orassign and or xor</PRE>
- <PRE>
- warn die lineseq nextstate scope enter leave setstate</PRE>
- <PRE>
- rv2cv anoncode prototype</PRE>
- <PRE>
- entersub leavesub leavesublv return method method_named -- XXX loops via recursion?</PRE>
- <PRE>
- leaveeval -- needed for Safe to operate, is safe without entereval</PRE>
- <DT><STRONG><A NAME="item_%3Abase_mem">:base_mem</A></STRONG><BR>
- <DD>
- These memory related ops are not included in :base_core because they
- can easily be used to implement a resource attack (e.g., consume all
- available memory).
- <PRE>
- concat repeat join range</PRE>
- <PRE>
- anonlist anonhash</PRE>
- <P>Note that despite the existance of this optag a memory resource attack
- may still be possible using only :base_core ops.</P>
- <P>Disabling these ops is a <EM>very</EM> heavy handed way to attempt to prevent
- a memory resource attack. It's probable that a specific memory limit
- mechanism will be added to perl in the near future.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%3Abase_loop">:base_loop</A></STRONG><BR>
- <DD>
- These loop ops are not included in :base_core because they can easily be
- used to implement a resource attack (e.g., consume all available CPU time).
- <PRE>
- grepstart grepwhile
- mapstart mapwhile
- enteriter iter
- enterloop leaveloop unstack
- last next redo
- goto</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Abase_io">:base_io</A></STRONG><BR>
- <DD>
- These ops enable <EM>filehandle</EM> (rather than filename) based input and
- output. These are safe on the assumption that only pre-existing
- filehandles are available for use. To create new filehandles other ops
- such as open would need to be enabled.
- <PRE>
- readline rcatline getc read</PRE>
- <PRE>
- formline enterwrite leavewrite</PRE>
- <PRE>
- print sysread syswrite send recv</PRE>
- <PRE>
- eof tell seek sysseek</PRE>
- <PRE>
- readdir telldir seekdir rewinddir</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Abase_orig">:base_orig</A></STRONG><BR>
- <DD>
- These are a hotchpotch of opcodes still waiting to be considered
- <PRE>
- gvsv gv gelem</PRE>
- <PRE>
- padsv padav padhv padany</PRE>
- <PRE>
- rv2gv refgen srefgen ref</PRE>
- <PRE>
- bless -- could be used to change ownership of objects (reblessing)</PRE>
- <PRE>
- pushre regcmaybe regcreset regcomp subst substcont</PRE>
- <PRE>
- sprintf prtf -- can core dump</PRE>
- <PRE>
- crypt</PRE>
- <PRE>
- tie untie</PRE>
- <PRE>
- dbmopen dbmclose
- sselect select
- pipe_op sockpair</PRE>
- <PRE>
- getppid getpgrp setpgrp getpriority setpriority localtime gmtime</PRE>
- <PRE>
- entertry leavetry -- can be used to 'hide' fatal errors</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Abase_math">:base_math</A></STRONG><BR>
- <DD>
- These ops are not included in :base_core because of the risk of them being
- used to generate floating point exceptions (which would have to be caught
- using a $SIG{FPE} handler).
- <PRE>
- atan2 sin cos exp log sqrt</PRE>
- <P>These ops are not included in :base_core because they have an effect
- beyond the scope of the compartment.</P>
- <PRE>
- rand srand</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Abase_thread">:base_thread</A></STRONG><BR>
- <DD>
- These ops are related to multi-threading.
- <PRE>
- lock threadsv</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Adefault">:default</A></STRONG><BR>
- <DD>
- A handy tag name for a <EM>reasonable</EM> default set of ops. (The current ops
- allowed are unstable while development continues. It will change.)
- <PRE>
- :base_core :base_mem :base_loop :base_io :base_orig :base_thread</PRE>
- <P>If safety matters to you (and why else would you be using the Opcode module?)
- then you should not rely on the definition of this, or indeed any other, optag!</P>
- <P></P>
- <DT><STRONG><A NAME="item_%3Afilesys_read">:filesys_read</A></STRONG><BR>
- <DD>
- <PRE>
- stat lstat readlink</PRE>
- <PRE>
- ftatime ftblk ftchr ftctime ftdir fteexec fteowned fteread
- ftewrite ftfile ftis ftlink ftmtime ftpipe ftrexec ftrowned
- ftrread ftsgid ftsize ftsock ftsuid fttty ftzero ftrwrite ftsvtx</PRE>
- <PRE>
- fttext ftbinary</PRE>
- <PRE>
- fileno</PRE>
- <DT><STRONG><A NAME="item_%3Asys_db">:sys_db</A></STRONG><BR>
- <DD>
- <PRE>
- ghbyname ghbyaddr ghostent shostent ehostent -- hosts
- gnbyname gnbyaddr gnetent snetent enetent -- networks
- gpbyname gpbynumber gprotoent sprotoent eprotoent -- protocols
- gsbyname gsbyport gservent sservent eservent -- services</PRE>
- <PRE>
- gpwnam gpwuid gpwent spwent epwent getlogin -- users
- ggrnam ggrgid ggrent sgrent egrent -- groups</PRE>
- <DT><STRONG><A NAME="item_%3Abrowse">:browse</A></STRONG><BR>
- <DD>
- A handy tag name for a <EM>reasonable</EM> default set of ops beyond the
- :default optag. Like :default (and indeed all the other optags) its
- current definition is unstable while development continues. It will change.
- <P>The :browse tag represents the next step beyond :default. It it a
- superset of the :default ops and adds :filesys_read the :sys_db.
- The intent being that scripts can access more (possibly sensitive)
- information about your system but not be able to change it.</P>
- <PRE>
- :default :filesys_read :sys_db</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Afilesys_open">:filesys_open</A></STRONG><BR>
- <DD>
- <PRE>
- sysopen open close
- umask binmode</PRE>
- <PRE>
- open_dir closedir -- other dir ops are in :base_io</PRE>
- <DT><STRONG><A NAME="item_%3Afilesys_write">:filesys_write</A></STRONG><BR>
- <DD>
- <PRE>
- link unlink rename symlink truncate</PRE>
- <PRE>
- mkdir rmdir</PRE>
- <PRE>
- utime chmod chown</PRE>
- <PRE>
- fcntl -- not strictly filesys related, but possibly as dangerous?</PRE>
- <DT><STRONG><A NAME="item_%3Asubprocess">:subprocess</A></STRONG><BR>
- <DD>
- <PRE>
- backtick system</PRE>
- <PRE>
- fork</PRE>
- <PRE>
- wait waitpid</PRE>
- <PRE>
- glob -- access to Cshell via <`rm *`></PRE>
- <DT><STRONG><A NAME="item_%3Aownprocess">:ownprocess</A></STRONG><BR>
- <DD>
- <PRE>
- exec exit kill</PRE>
- <PRE>
- time tms -- could be used for timing attacks (paranoid?)</PRE>
- <DT><STRONG><A NAME="item_%3Aothers">:others</A></STRONG><BR>
- <DD>
- This tag holds groups of assorted specialist opcodes that don't warrant
- having optags defined for them.
- <P>SystemV Interprocess Communications:</P>
- <PRE>
- msgctl msgget msgrcv msgsnd</PRE>
- <PRE>
- semctl semget semop</PRE>
- <PRE>
- shmctl shmget shmread shmwrite</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%3Astill_to_be_decided">:still_to_be_decided</A></STRONG><BR>
- <DD>
- <PRE>
- chdir
- flock ioctl</PRE>
- <PRE>
- socket getpeername ssockopt
- bind connect listen accept shutdown gsockopt getsockname</PRE>
- <PRE>
- sleep alarm -- changes global timer state and signal handling
- sort -- assorted problems including core dumps
- tied -- can be used to access object implementing a tie
- pack unpack -- can be used to create/use memory pointers</PRE>
- <PRE>
- entereval -- can be used to hide code from initial compile
- require dofile</PRE>
- <PRE>
- caller -- get info about calling environment and args</PRE>
- <PRE>
- reset</PRE>
- <PRE>
- dbstate -- perl -d version of nextstate(ment) opcode</PRE>
- <DT><STRONG><A NAME="item_%3Adangerous">:dangerous</A></STRONG><BR>
- <DD>
- This tag is simply a bucket for opcodes that are unlikely to be used via
- a tag name but need to be tagged for completness and documentation.
- <PRE>
- syscall dump chroot</PRE>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><CODE>ops(3)</CODE> -- perl pragma interface to Opcode module.</P>
- <P><CODE>Safe(3)</CODE> -- Opcode and namespace limited execution compartments</P>
- <P>
- <HR>
- <H1><A NAME="authors">AUTHORS</A></H1>
- <P>Originally designed and implemented by Malcolm Beattie,
- <A HREF="mailto:mbeattie@sable.ox.ac.uk">mbeattie@sable.ox.ac.uk</A> as part of Safe version 1.</P>
- <P>Split out from Safe module version 1, named opcode tags and other
- changes added by Tim Bunce.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Opcode - Disable named opcodes when compiling perl code</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-