Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Proposed change regarding "Taint" support [overhead]

by kcott (Bishop)
on Aug 13, 2021 at 23:47 UTC ( #11135833=note: print w/replies, xml ) Need Help??


in reply to Proposed change regarding "Taint" support

G'day Rob,

Thanks for advising of this proposal.

I was wondering about the taint-related overhead. I'm not an XS programmer; however, I did some investigation using Devel::Peek and followed that up with some hunting around in perlguts.

I'm genuinely interested in learning about this. My investigations are potentially incomplete and my inferences could easily be wrong. Any constructive criticism would be welcome.

Without any implicit (setuid/getuid) or explicit (-T) taint checking:

$ perl -e 'use Devel::Peek; my $x = $ENV{PATH}; Dump $x' SV = PVMG(0x8000c68f0) at 0x80008a8b8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) IV = 0 NV = 0 PV = 0x80008c2c0 "... long list of pathnames ..."\0 CUR = 2026 LEN = 2028 COW_REFCNT = 1 $ perl -e 'use Devel::Peek; my $x = q{$ENV{PATH}}; Dump $x' SV = PV(0x800004670) at 0x80008a8a8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x80008e250 "$ENV{PATH}"\0 CUR = 10 LEN = 12 COW_REFCNT = 1

So, ignoring the hex numbers — which I assumed were related to memory locations, like HASH(0x800003c88), ARRAY(0x800003cd0), etc. — and the values directly related to the string content, it would seem that the elements taking part in any overhead are SV = PVMG (cf. SV = PV) and the additional IV and NV. I wasn't able to figure out exactly what that overhead might be.

Now, I could be barking up the wrong tree, which is entirely possible, and, if so, please correct my conclusions. It seems there is no overhead unless there are tainted variables. Is there something else going on that I've overlooked or, perhaps, that I'm simply unaware of?

For comparison and completeness, here's the Devel::Peek output when -T is used:

$ perl -Te 'use Devel::Peek; my $x = $ENV{PATH}; Dump $x' SV = PVMG(0x8000c8850) at 0x80008b7d8 REFCNT = 1 FLAGS = (GMG,SMG,POK,IsCOW,pPOK) IV = 0 NV = 0 PV = 0x80008de60 "... long list of pathnames ..."\0 CUR = 2026 LEN = 2028 COW_REFCNT = 1 MAGIC = 0x8000447c0 MG_VIRTUAL = &PL_vtbl_taint MG_TYPE = PERL_MAGIC_taint(t) MG_LEN = 1 $ perl -Te 'use Devel::Peek; my $x = q{$ENV{PATH}}; Dump $x' SV = PV(0x800004670) at 0x80008bee8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x800090220 "$ENV{PATH}"\0 CUR = 10 LEN = 12 COW_REFCNT = 1

There's no change for the untainted $x. The tainted version has additional FLAGS and a new MAGIC section. I had found PERL_MAGIC_taint in perlguts and originally thought that was related to PVMG (but maybe that's wrong).

— Ken

Replies are listed 'Best First'.
Re^2: Proposed change regarding "Taint" support [overhead]
by syphilis (Archbishop) on Aug 14, 2021 at 02:39 UTC
    Hi Ken,

    Looking at Steffen Mueller's original post on the idea, it seems that it achieves its speed up by turning taint-related operations (that normally get processed even when not running under -T) into no-ops.
    As such, I expect you'll need to build a perl with -DNO_TAINT_SUPPORT in order to measure any speed improvements.

    I've built such a version of current blead (on Windows), but haven't yet run any benchmarks.
    To build it, I just hacked perl.h by inserting
    #define SILENT_NO_TAINT_SUPPORT 1
    just before (the already existing)
    #if defined(SILENT_NO_TAINT_SUPPORT) && !defined(NO_TAINT_SUPPORT) # define NO_TAINT_SUPPORT 1 #endif
    and then built perl in the usual way.
    That seems to have resulted in the desired build. To use your first example:
    perl -Te "use Devel::Peek; my $x = $ENV{PATH}; Dump $x;" SV = PVMG(0x5d1fc8) at 0x56e6f8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) IV = 0 NV = 0 PV = 0x575628 "... long list of pathnames ..."\0 CUR = 852 LEN = 854 COW_REFCNT = 1
    Note the absence of the "magic" flags.

    Running make test on that build results in a number of failures. This is expected because some scripts do not cater for the possibility that -T is now a no-op.
    Perhaps there are additional (ie unexpected) failures, too ... I don't know.
    See below for the full test summary report.

    Cheers,
    Rob

      ++ Many thanks for this. There's clearly a lot going on under the hood that I wasn't aware of; particularly with respect to "... normally get processed even when not running under -T ...".

      I decided to have a bit of a nose around some of the various items you discussed. The repo link on https://metacpan.org/pod/perl handily took me to the blead branch of the "Github - Perl/perl5" page.

      More of a curiosity than anything related to tainting; my eye was drawn to the browser tab which appeared to have the emoji for a Bactrian camel (🐫) rather than the usual Dromedary camel (🐪). The text on the tab is very small and I thought that maybe I was miscounting the humps 😕; but no, on checking the source, it appears on two lines:

        <title>GitHub - Perl/perl5: 🐫 The Perl programming language</title>
          <meta name="description" content="🐫 The Perl programming language ...>
      

      I thought this was odd, but then had a vague recollection of there being an O'Reilly ™, ® or © associated with the camel image when used with Perl. After searching through a number of O'Reilly, Perl.com and Perl.org pages, I finally found it in "perl.org - Site Information". Of course, I may be overthinking this; it could just be a typo: &#1212483; instead of &#1212482;.

      Anyway, back to tainting. I located perl.h — that was very generous of you to void your warranty to help me. :-)

      /* By compiling a perl with -DNO_TAINT_SUPPORT or -DSILENT_NO_TAINT_SU +PPORT, * ... * * DANGER! Using NO_TAINT_SUPPORT or SILENT_NO_TAINT_SUPPORT * voids your nonexistent warranty! */

      I also looked in the t/ directory for the tests you indicated had failed: run/switcht.t was OK with only 66 lines; op/taint.t was somewhat more daunting with 2,986 lines (I didn't read it all). Realising that there was probably tens of thousands of lines in total, I left it there.

      Thanks again.

      — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-01-26 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?