Debian Codegraph @

upstream/debian-unstable/man3/Opcode.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Opcode 3perl"
58 .TH Opcode 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Opcode \- Disable named opcodes when compiling perl code
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& use Opcode;
69 .Ve
70 .SH DESCRIPTION
71 .IX Header "DESCRIPTION"
72 Perl code is always compiled into an internal format before execution.
73 .PP
74 Evaluating perl code (e.g. via "eval" or "do 'file'") causes
75 the code to be compiled into an internal format and then,
76 provided there was no error in the compilation, executed.
77 The internal format is based on many distinct \fIopcodes\fR.
78 .PP
79 By default no opmask is in effect and any code can be compiled.
80 .PP
81 The Opcode module allow you to define an \fIoperator mask\fR to be in
82 effect when perl \fInext\fR compiles any code. Attempting to compile code
83 which contains a masked opcode will cause the compilation to fail
84 with an error. The code will not be executed.
85 .SH NOTE
86 .IX Header "NOTE"
87 The Opcode module is not usually used directly. See the ops pragma and
88 Safe modules for more typical uses.
89 .SH WARNING
90 .IX Header "WARNING"
91 The Opcode module does not implement an effective sandbox for
92 evaluating untrusted code with the perl interpreter.
93 .PP
94 Bugs in the perl interpreter that could be abused to bypass
95 Opcode restrictions are not treated as vulnerabilities. See
96 perlsecpolicy for additional information.
97 .PP
98 The authors make \fBno warranty\fR, implied or otherwise, about the
99 suitability of this software for safety or security purposes.
100 .PP
101 The authors shall not in any case be liable for special, incidental,
102 consequential, indirect or other similar damages arising from the use
103 of this software.
104 .PP
105 Your mileage will vary. If in any doubt \fBdo not use it\fR.
106 .SH "Operator Names and Operator Lists"
107 .IX Header "Operator Names and Operator Lists"
108 The canonical list of operator names is the contents of the array
109 PL_op_name defined and initialised in file \fIopcode.h\fR of the Perl
110 source distribution (and installed into the perl library).
111 .PP
112 Each operator has both a terse name (its opname) and a more verbose or
113 recognisable descriptive name. The opdesc function can be used to
114 return a list of descriptions for a list of operators.
115 .PP
116 Many of the functions and methods listed below take a list of
117 operators as parameters. Most operator lists can be made up of several
118 types of element. Each element can be one of
119 .IP "an operator name (opname)" 8
120 .IX Item "an operator name (opname)"
121 Operator names are typically small lowercase words like enterloop,
122 leaveloop, last, next, redo etc. Sometimes they are rather cryptic
123 like gv2cv, i_ncmp and ftsvtx.
124 .IP "an operator tag name (optag)" 8
125 .IX Item "an operator tag name (optag)"
126 Operator tags can be used to refer to groups (or sets) of operators.
127 Tag names always begin with a colon. The Opcode module defines several
128 optags and the user can define others using the define_optag function.
129 .IP "a negated opname or optag" 8
130 .IX Item "a negated opname or optag"
131 An opname or optag can be prefixed with an exclamation mark, e.g., !mkdir.
132 Negating an opname or optag means remove the corresponding ops from the
133 accumulated set of ops at that point.
134 .IP "an operator set (opset)" 8
135 .IX Item "an operator set (opset)"
136 An \fIopset\fR as a binary string of approximately 44 bytes which holds a
137 set or zero or more operators.
138 .Sp
139 The opset and opset_to_ops functions can be used to convert from
140 a list of operators to an opset and \fIvice versa\fR.
141 .Sp
142 Wherever a list of operators can be given you can use one or more opsets.
143 See also Manipulating Opsets below.
144 .SH "Opcode Functions"
145 .IX Header "Opcode Functions"
146 The Opcode package contains functions for manipulating operator names
147 tags and sets. All are available for export by the package.
148 .IP opcodes 8
149 .IX Item "opcodes"
150 In a scalar context opcodes returns the number of opcodes in this
151 version of perl (around 350 for perl\-5.7.0).
152 .Sp
153 In a list context it returns a list of all the operator names.
154 (Not yet implemented, use \f(CW@names\fR = opset_to_ops(full_opset).)
155 .IP "opset (OP, ...)" 8
156 .IX Item "opset (OP, ...)"
157 Returns an opset containing the listed operators.
158 .IP "opset_to_ops (OPSET)" 8
159 .IX Item "opset_to_ops (OPSET)"
160 Returns a list of operator names corresponding to those operators in
161 the set.
162 .IP "opset_to_hex (OPSET)" 8
163 .IX Item "opset_to_hex (OPSET)"
164 Returns a string representation of an opset. Can be handy for debugging.
165 .IP full_opset 8
166 .IX Item "full_opset"
167 Returns an opset which includes all operators.
168 .IP empty_opset 8
169 .IX Item "empty_opset"
170 Returns an opset which contains no operators.
171 .IP "invert_opset (OPSET)" 8
172 .IX Item "invert_opset (OPSET)"
173 Returns an opset which is the inverse set of the one supplied.
174 .IP "verify_opset (OPSET, ...)" 8
175 .IX Item "verify_opset (OPSET, ...)"
176 Returns true if the supplied opset looks like a valid opset (is the
177 right length etc) otherwise it returns false. If an optional second
178 parameter is true then verify_opset will croak on an invalid opset
179 instead of returning false.
180 .Sp
181 Most of the other Opcode functions call verify_opset automatically
182 and will croak if given an invalid opset.
183 .IP "define_optag (OPTAG, OPSET)" 8
184 .IX Item "define_optag (OPTAG, OPSET)"
185 Define OPTAG as a symbolic name for OPSET. Optag names always start
186 with a colon \f(CW\*(C`:\*(C'\fR.
187 .Sp
188 The optag name used must not be defined already (define_optag will
189 croak if it is already defined). Optag names are global to the perl
190 process and optag definitions cannot be altered or deleted once
191 defined.
192 .Sp
193 It is strongly recommended that applications using Opcode should use a
194 leading capital letter on their tag names since lowercase names are
195 reserved for use by the Opcode module. If using Opcode within a module
196 you should prefix your tags names with the name of your module to
197 ensure uniqueness and thus avoid clashes with other modules.
198 .IP "opmask_add (OPSET)" 8
199 .IX Item "opmask_add (OPSET)"
200 Adds the supplied opset to the current opmask. Note that there is
201 currently \fIno\fR mechanism for unmasking ops once they have been masked.
202 This is intentional.
203 .IP opmask 8
204 .IX Item "opmask"
205 Returns an opset corresponding to the current opmask.
206 .IP "opdesc (OP, ...)" 8
207 .IX Item "opdesc (OP, ...)"
208 This takes a list of operator names and returns the corresponding list
209 of operator descriptions.
210 .IP "opdump (PAT)" 8
211 .IX Item "opdump (PAT)"
212 Dumps to STDOUT a two column list of op names and op descriptions.
213 If an optional pattern is given then only lines which match the
214 (case insensitive) pattern will be output.
215 .Sp
216 It's designed to be used as a handy command line utility:
217 .Sp
218 .Vb 2
219 \& perl \-MOpcode=opdump \-e opdump
220 \& perl \-MOpcode=opdump \-e \*(Aqopdump Eval\*(Aq
221 .Ve
222 .SH "Manipulating Opsets"
223 .IX Header "Manipulating Opsets"
224 Opsets may be manipulated using the perl bit vector operators & (and), | (or),
225 ^ (xor) and ~ (negate/invert).
226 .PP
227 However you should never rely on the numerical position of any opcode
228 within the opset. In other words both sides of a bit vector operator
229 should be opsets returned from Opcode functions.
230 .PP
231 Also, since the number of opcodes in your current version of perl might
232 not be an exact multiple of eight, there may be unused bits in the last
233 byte of an upset. This should not cause any problems (Opcode functions
234 ignore those extra bits) but it does mean that using the ~ operator
235 will typically not produce the same 'physical' opset 'string' as the
236 invert_opset function.
237 .SH "TO DO (maybe)"
238 .IX Header "TO DO (maybe)"
239 .Vb 3
240 \& $bool = opset_eq($opset1, $opset2) true if opsets are logically
241 \& equivalent
242 \& $yes = opset_can($opset, @ops) true if $opset has all @ops set
243 \&
244 \& @diff = opset_diff($opset1, $opset2) => (\*(Aqfoo\*(Aq, \*(Aq!bar\*(Aq, ...)
245 .Ve
246 .SH "Predefined Opcode Tags"
247 .IX Header "Predefined Opcode Tags"
248 .IP :base_core 5
249 .IX Item ":base_core"
250 .Vb 1
251 \& null stub scalar pushmark wantarray const defined undef
252 \&
253 \& rv2sv sassign padsv_store
254 \&
255 \& rv2av aassign aelem aelemfast aelemfast_lex aslice kvaslice
256 \& av2arylen aelemfastlex_store
257 \&
258 \& rv2hv helem hslice kvhslice each values keys exists delete
259 \& aeach akeys avalues multideref argelem argdefelem argcheck
260 \&
261 \& preinc i_preinc predec i_predec postinc i_postinc
262 \& postdec i_postdec int hex oct abs pow multiply i_multiply
263 \& divide i_divide modulo i_modulo add i_add subtract i_subtract
264 \&
265 \& left_shift right_shift bit_and bit_xor bit_or nbit_and
266 \& nbit_xor nbit_or sbit_and sbit_xor sbit_or negate i_negate not
267 \& complement ncomplement scomplement
268 \&
269 \& lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp
270 \& slt sgt sle sge seq sne scmp
271 \& isa
272 \&
273 \& substr vec stringify study pos length index rindex ord chr
274 \&
275 \& ucfirst lcfirst uc lc fc quotemeta trans transr chop schop
276 \& chomp schomp
277 \&
278 \& match split qr
279 \&
280 \& list lslice splice push pop shift unshift reverse
281 \&
282 \& cond_expr flip flop andassign orassign dorassign and or dor xor
283 \& helemexistsor
284 \&
285 \& warn die lineseq nextstate scope enter leave
286 \&
287 \& rv2cv anoncode prototype coreargs avhvswitch anonconst
288 \& emptyavhv
289 \&
290 \& entersub leavesub leavesublv return method method_named
291 \& method_super method_redir method_redir_super
292 \& \-\- XXX loops via recursion?
293 \&
294 \& cmpchain_and cmpchain_dup
295 \&
296 \& is_bool
297 \& is_weak weaken unweaken
298 \&
299 \& leaveeval \-\- needed for Safe to operate, is safe
300 \& without entereval
301 \&
302 \& methstart initfield
303 .Ve
304 .IP :base_mem 5
305 .IX Item ":base_mem"
306 These memory related ops are not included in :base_core because they
307 can easily be used to implement a resource attack (e.g., consume all
308 available memory).
309 .Sp
310 .Vb 1
311 \& concat multiconcat repeat join range
312 \&
313 \& anonlist anonhash
314 .Ve
315 .Sp
316 Note that despite the existence of this optag a memory resource attack
317 may still be possible using only :base_core ops.
318 .Sp
319 Disabling these ops is a \fIvery\fR heavy handed way to attempt to prevent
320 a memory resource attack. It's probable that a specific memory limit
321 mechanism will be added to perl in the near future.
322 .IP :base_loop 5
323 .IX Item ":base_loop"
324 These loop ops are not included in :base_core because they can easily be
325 used to implement a resource attack (e.g., consume all available CPU time).
326 .Sp
327 .Vb 6
328 \& grepstart grepwhile
329 \& mapstart mapwhile
330 \& enteriter iter
331 \& enterloop leaveloop unstack
332 \& last next redo
333 \& goto
334 .Ve
335 .IP :base_io 5
336 .IX Item ":base_io"
337 These ops enable \fIfilehandle\fR (rather than filename) based input and
338 output. These are safe on the assumption that only pre-existing
339 filehandles are available for use. Usually, to create new filehandles
340 other ops such as open would need to be enabled, if you don't take into
341 account the magical open of ARGV.
342 .Sp
343 .Vb 1
344 \& readline rcatline getc read
345 \&
346 \& formline enterwrite leavewrite
347 \&
348 \& print say sysread syswrite send recv
349 \&
350 \& eof tell seek sysseek
351 \&
352 \& readdir telldir seekdir rewinddir
353 .Ve
354 .IP :base_orig 5
355 .IX Item ":base_orig"
356 These are a hotchpotch of opcodes still waiting to be considered
357 .Sp
358 .Vb 1
359 \& gvsv gv gelem
360 \&
361 \& padsv padav padhv padcv padany padrange introcv clonecv
362 \&
363 \& once
364 \&
365 \& rv2gv refgen srefgen ref refassign lvref lvrefslice lvavref
366 \& blessed refaddr reftype
367 \&
368 \& bless \-\- could be used to change ownership of objects
369 \& (reblessing)
370 \&
371 \& regcmaybe regcreset regcomp subst substcont
372 \&
373 \& sprintf prtf \-\- can core dump
374 \&
375 \& crypt
376 \&
377 \& tie untie
378 \&
379 \& dbmopen dbmclose
380 \& sselect select
381 \& pipe_op sockpair
382 \&
383 \& getppid getpgrp setpgrp getpriority setpriority
384 \& localtime gmtime
385 \&
386 \& entertry leavetry \-\- can be used to \*(Aqhide\*(Aq fatal errors
387 \& entertrycatch poptry catch leavetrycatch \-\- similar
388 \&
389 \& entergiven leavegiven
390 \& enterwhen leavewhen
391 \& break continue
392 \& smartmatch
393 \&
394 \& pushdefer
395 \&
396 \& custom \-\- where should this go
397 \&
398 \& ceil floor
399 \&
400 \& is_tainted
401 .Ve
402 .IP :base_math 5
403 .IX Item ":base_math"
404 These ops are not included in :base_core because of the risk of them being
405 used to generate floating point exceptions (which would have to be caught
406 using a \f(CW$SIG\fR{FPE} handler).
407 .Sp
408 .Vb 1
409 \& atan2 sin cos exp log sqrt
410 .Ve
411 .Sp
412 These ops are not included in :base_core because they have an effect
413 beyond the scope of the compartment.
414 .Sp
415 .Vb 1
416 \& rand srand
417 .Ve
418 .IP :base_thread 5
419 .IX Item ":base_thread"
420 These ops are related to multi-threading.
421 .Sp
422 .Vb 1
423 \& lock
424 .Ve
425 .IP :default 5
426 .IX Item ":default"
427 A handy tag name for a \fIreasonable\fR default set of ops. (The current ops
428 allowed are unstable while development continues. It will change.)
429 .Sp
430 .Vb 1
431 \& :base_core :base_mem :base_loop :base_orig :base_thread
432 .Ve
433 .Sp
434 This list used to contain :base_io prior to Opcode 1.07.
435 .Sp
436 If safety matters to you (and why else would you be using the Opcode module?)
437 then you should not rely on the definition of this, or indeed any other, optag!
438 .IP :filesys_read 5
439 .IX Item ":filesys_read"
440 .Vb 1
441 \& stat lstat readlink
442 \&
443 \& ftatime ftblk ftchr ftctime ftdir fteexec fteowned
444 \& fteread ftewrite ftfile ftis ftlink ftmtime ftpipe
445 \& ftrexec ftrowned ftrread ftsgid ftsize ftsock ftsuid
446 \& fttty ftzero ftrwrite ftsvtx
447 \&
448 \& fttext ftbinary
449 \&
450 \& fileno
451 .Ve
452 .IP :sys_db 5
453 .IX Item ":sys_db"
454 .Vb 4
455 \& ghbyname ghbyaddr ghostent shostent ehostent \-\- hosts
456 \& gnbyname gnbyaddr gnetent snetent enetent \-\- networks
457 \& gpbyname gpbynumber gprotoent sprotoent eprotoent \-\- protocols
458 \& gsbyname gsbyport gservent sservent eservent \-\- services
459 \&
460 \& gpwnam gpwuid gpwent spwent epwent getlogin \-\- users
461 \& ggrnam ggrgid ggrent sgrent egrent \-\- groups
462 .Ve
463 .IP :browse 5
464 .IX Item ":browse"
465 A handy tag name for a \fIreasonable\fR default set of ops beyond the
466 :default optag. Like :default (and indeed all the other optags) its
467 current definition is unstable while development continues. It will change.
468 .Sp
469 The :browse tag represents the next step beyond :default. It is a
470 superset of the :default ops and adds :filesys_read the :sys_db.
471 The intent being that scripts can access more (possibly sensitive)
472 information about your system but not be able to change it.
473 .Sp
474 .Vb 1
475 \& :default :filesys_read :sys_db
476 .Ve
477 .IP :filesys_open 5
478 .IX Item ":filesys_open"
479 .Vb 2
480 \& sysopen open close
481 \& umask binmode
482 \&
483 \& open_dir closedir \-\- other dir ops are in :base_io
484 .Ve
485 .IP :filesys_write 5
486 .IX Item ":filesys_write"
487 .Vb 1
488 \& link unlink rename symlink truncate
489 \&
490 \& mkdir rmdir
491 \&
492 \& utime chmod chown
493 \&
494 \& fcntl \-\- not strictly filesys related, but possibly as
495 \& dangerous?
496 .Ve
497 .IP :subprocess 5
498 .IX Item ":subprocess"
499 .Vb 1
500 \& backtick system
501 \&
502 \& fork
503 \&
504 \& wait waitpid
505 \&
506 \& glob \-\- access to Cshell via <\`rm *\`>
507 .Ve
508 .IP :ownprocess 5
509 .IX Item ":ownprocess"
510 .Vb 1
511 \& exec exit kill
512 \&
513 \& time tms \-\- could be used for timing attacks (paranoid?)
514 .Ve
515 .IP :others 5
516 .IX Item ":others"
517 This tag holds groups of assorted specialist opcodes that don't warrant
518 having optags defined for them.
519 .Sp
520 SystemV Interprocess Communications:
521 .Sp
522 .Vb 1
523 \& msgctl msgget msgrcv msgsnd
524 \&
525 \& semctl semget semop
526 \&
527 \& shmctl shmget shmread shmwrite
528 .Ve
529 .IP :load 5
530 .IX Item ":load"
531 This tag holds opcodes related to loading modules and getting information
532 about calling environment and args.
533 .Sp
534 .Vb 2
535 \& require dofile
536 \& caller runcv classname
537 .Ve
538 .IP :still_to_be_decided 5
539 .IX Item ":still_to_be_decided"
540 .Vb 2
541 \& chdir
542 \& flock ioctl
543 \&
544 \& socket getpeername ssockopt
545 \& bind connect listen accept shutdown gsockopt getsockname
546 \&
547 \& sleep alarm \-\- changes global timer state and signal handling
548 \& sort \-\- assorted problems including core dumps
549 \& tied \-\- can be used to access object implementing a tie
550 \& pack unpack \-\- can be used to create/use memory pointers
551 \&
552 \& hintseval \-\- constant op holding eval hints
553 \&
554 \& entereval \-\- can be used to hide code from initial compile
555 \&
556 \& reset
557 \&
558 \& dbstate \-\- perl \-d version of nextstate(ment) opcode
559 .Ve
560 .IP :dangerous 5
561 .IX Item ":dangerous"
562 This tag is simply a bucket for opcodes that are unlikely to be used via
563 a tag name but need to be tagged for completeness and documentation.
564 .Sp
565 .Vb 1
566 \& syscall dump chroot
567 .Ve
568 .SH "SEE ALSO"
569 .IX Header "SEE ALSO"
570 ops \-\- perl pragma interface to Opcode module.
571 .PP
572 Safe \-\- Opcode and namespace limited execution compartments
573 .SH AUTHORS
574 .IX Header "AUTHORS"
575 Originally designed and implemented by Malcolm Beattie,
576 [email protected] as part of Safe version 1.
577 .PP
578 Split out from Safe module version 1, named opcode tags and other
579 changes added by Tim Bunce.