home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5319 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  7.5 KB

  1. Path: sparky!uunet!eiffel!eiffel.com
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Newsgroups: comp.lang.perl
  4. Subject: Official patch for perload script
  5. Summary: perload forgot about taintperl
  6. Keywords: autoloading, dataloading, taintperl, bug
  7. Message-ID: <114@eiffel.eiffel.com>
  8. Date: 14 Aug 92 17:00:48 GMT
  9. Sender: ram@eiffel.com
  10. Organization: Interactive Software Engineering, Santa Barbara CA
  11. Lines: 226
  12.  
  13. Laurence Yaffe <lgy@landau.phys.washington.edu> was kind enough to
  14. bring to my attention the fact that perload did not consider setuid
  15. scripts.
  16.  
  17. Actually, there seems to be a severe bug in taintperl which causes it
  18. to loop when eval'ing a tainted variable, but this bug does not manifest
  19. at once. It is a latent one, the most dangerous kind :-)
  20.  
  21. What happens with perl 4.0 PL35 is that perl reports the following
  22. message:
  23.  
  24.     Warning: something's wrong at utest.dl line 374.
  25.  
  26. instead of the expected:
  27.  
  28.     Insecure dependency in eval at utest.dl line 374.
  29.  
  30. Ok... Here is the patch which solves this problem by forcing an untainting
  31. of the loaded function body before eval'ing it. You need to use the new -t
  32. option of perload to force those checks. They introduce some slight overhead,
  33. which is why they are made optional (but unless you have CPU cycles to waste,
  34. the -t option is useless if you do not expect your script to be run as
  35. setuid -- or setgid, I presume).
  36.  
  37. Thanks again Laurence for letting me know about this problem.
  38. --
  39. Raphael Manfredi <ram@eiffel.com>
  40. Interactive Software Engineering Inc.
  41. 270 Storke Road, Suite #7                      / Tel +1 (805) 685-1006 \
  42. Goleta, California 93117, USA                  \ Fax +1 (805) 685-6869 /
  43.  
  44.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  45. Following is the patch for perload. To apply, simply run
  46.  
  47.     patch -N < this_article
  48.  
  49. where "this_article" is a saved copy of this article.
  50.  
  51. *** perload.old    Fri Aug 14 09:53:38 1992
  52. --- perload    Fri Aug 14 09:53:08 1992
  53. ***************
  54. *** 8,14 ****
  55.   # This perl script is its own manual page [generated by wrapman]
  56.   #
  57.   
  58. ! # $Id: perload,v 2.9.1.1 92/08/02 16:25:43 ram Exp Locker: ram $
  59.   #
  60.   #  Copyright (c) 1992, Raphael Manfredi
  61.   #
  62. --- 8,14 ----
  63.   # This perl script is its own manual page [generated by wrapman]
  64.   #
  65.   
  66. ! # $Id: perload,v 2.9.1.2 92/08/12 21:36:54 ram Exp Locker: ram $
  67.   #
  68.   #  Copyright (c) 1992, Raphael Manfredi
  69.   #
  70. ***************
  71. *** 16,21 ****
  72. --- 16,26 ----
  73.   #  Licence as specified in the README file that comes with dist.
  74.   #
  75.   # $Log:    perload,v $
  76. + # Revision 2.9.1.2  92/08/12  21:36:54  ram
  77. + # patch6: new -o option which optimizes dataloading by building an offset table
  78. + # patch6: loading routines now avoid unnecessary strings operations
  79. + # patch6: previous changes contributed by Wayne Scott <wscott@ecn.purdue.edu>
  80. + # 
  81.   # Revision 2.9.1.1  92/08/02  16:25:43  ram
  82.   # patch2: dataloading routines now fully operate in perload package
  83.   # 
  84. ***************
  85. *** 154,160 ****
  86.   }
  87.   
  88.   @auto = keys %Auto;
  89. ! print &q(<<'EOC') if @auto > 0;
  90.   :# Load the calling function from file and call it. This function is called
  91.   :# only once per file to be loaded.
  92.   :sub main'autoload {
  93. --- 159,166 ----
  94.   }
  95.   
  96.   @auto = keys %Auto;
  97. ! if (@auto > 0) {
  98. !     print &q(<<'EOC');
  99.   :# Load the calling function from file and call it. This function is called
  100.   :# only once per file to be loaded.
  101.   :sub main'autoload {
  102. ***************
  103. *** 191,197 ****
  104. --- 197,216 ----
  105.   :        $body .= $_;
  106.   :    }
  107.   :    close FILE;
  108. + EOC
  109. +     if ($opt_t) {
  110. +         print &q(<<'EOC');
  111. + :    # Untaint body when running setuid
  112. + :    $body =~ /^([^\0]*)/;
  113. + :    # No need to untaint $load, as it was built using trusted variables
  114. + :    eval $1 . $load;
  115. + EOC
  116. +     } else {
  117. +         print &q(<<'EOC');
  118.   :    eval $body . $load;
  119. + EOC
  120. +     }
  121. +     print &q(<<'EOC');
  122.   :    chop($@) && die "$@, while parsing code of $file.\n";
  123.   :}
  124.   :
  125. ***************
  126. *** 220,227 ****
  127.   :}
  128.   :
  129.   EOC
  130.   
  131. ! print &q(<<'EOC') if @Data > 0;
  132.   :# Load the calling function from DATA segment and call it. This function is
  133.   :# called only once per routine to be loaded.
  134.   :sub main'dataload {
  135. --- 239,248 ----
  136.   :}
  137.   :
  138.   EOC
  139. + }
  140.   
  141. ! if (@Data > 0) {
  142. !     print &q(<<'EOC');
  143.   :# Load the calling function from DATA segment and call it. This function is
  144.   :# called only once per routine to be loaded.
  145.   :sub main'dataload {
  146. ***************
  147. *** 253,265 ****
  148.   :    local($body) = scalar(<main'DATA>);
  149.   :    local($*) = 1;
  150.   :    die "End of file found while loading $_[0].\n" unless $body =~ /^\}$/;
  151.   :    eval $body;        # Load function into perl space
  152.   :    chop($@) && die "$@, while parsing code of $_[0].\n";
  153.   :}
  154.   :
  155.   EOC
  156. - if (@Data > 0) {
  157.       print &q(<<'EOC') unless $opt_o;
  158.   :# Parse text after the END token and record defined loadable functions (i.e.
  159.   :# those whose name starts with load_) into the %Datapos array. Such function
  160. --- 274,297 ----
  161.   :    local($body) = scalar(<main'DATA>);
  162.   :    local($*) = 1;
  163.   :    die "End of file found while loading $_[0].\n" unless $body =~ /^\}$/;
  164. + EOC
  165. +     if ($opt_t) {
  166. +         print &q(<<'EOC')
  167. + :    # Untaint body when running setuid
  168. + :    $body =~ /^([^\0]*)/;
  169. + :    # Now we may safely eval it without getting an insecure dependency
  170. + :    eval $1;        # Load function into perl space
  171. + EOC
  172. +     } else {
  173. +         print &q(<<'EOC');
  174.   :    eval $body;        # Load function into perl space
  175. + EOC
  176. +     }
  177. +     print &q(<<'EOC');
  178.   :    chop($@) && die "$@, while parsing code of $_[0].\n";
  179.   :}
  180.   :
  181.   EOC
  182.       print &q(<<'EOC') unless $opt_o;
  183.   :# Parse text after the END token and record defined loadable functions (i.e.
  184.   :# those whose name starts with load_) into the %Datapos array. Such function
  185. ***************
  186. *** 453,459 ****
  187.   perload \- builds up autoloaded and dataloaded perl scripts
  188.   .SH SYNOPSIS
  189.   .B perload
  190. ! [ \fB\-o\fR ]
  191.   [ \fIfile\fR ]
  192.   .SH DESCRIPTION
  193.   .I Perload
  194. --- 485,491 ----
  195.   perload \- builds up autoloaded and dataloaded perl scripts
  196.   .SH SYNOPSIS
  197.   .B perload
  198. ! [ \fB\-ot\fR ]
  199.   [ \fIfile\fR ]
  200.   .SH DESCRIPTION
  201.   .I Perload
  202. ***************
  203. *** 550,557 ****
  204.   directive (the inmost one). This does not turn off the \fIperload\fR processing
  205.   though. The \fIpath\fR name is optional here (in fact, it has only a comment
  206.   value).
  207. ! .SH OPTION
  208. ! Perload accepts only one option, \fB\-o\fR, which is meaningful only when
  209.   dataloading is used. It outputs an offset table which lists the relative
  210.   offset of the dataloaded functions within the data section. This will spare
  211.   perl the run-time parsing needed to locate the function, and results in an good
  212. --- 582,589 ----
  213.   directive (the inmost one). This does not turn off the \fIperload\fR processing
  214.   though. The \fIpath\fR name is optional here (in fact, it has only a comment
  215.   value).
  216. ! .SH OPTIONS
  217. ! Perload accepts only two options. Using \fB\-o\fR is meaningful only when
  218.   dataloading is used. It outputs an offset table which lists the relative
  219.   offset of the dataloaded functions within the data section. This will spare
  220.   perl the run-time parsing needed to locate the function, and results in an good
  221. ***************
  222. *** 564,569 ****
  223. --- 596,607 ----
  224.   section is necessary for whatever reason. When \fB\-o\fR is used, any
  225.   change in the dataloaded function must be committed by re-running perload
  226.   on the original script.
  227. + .PP
  228. + The other option \fB\-t\fR is to be used when producing a script which is
  229. + going to run setuid. The body of the loaded function is untainted before being
  230. + fed to eval, which slightly slows down loading (the first time the function is
  231. + called), but avoids either an insecure dependency report or weird warnings from
  232. + taintperl stating something is wrong (which is the behaviour with 4.0 PL35).
  233.   .SH FILES
  234.   .TP 10
  235.   auto
  236.  
  237. ### End of patch ###
  238.