Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move . to the end of the library search path #368

Closed
sorear opened this issue Apr 24, 2010 · 16 comments
Closed

Move . to the end of the library search path #368

sorear opened this issue Apr 24, 2010 · 16 comments

Comments

@sorear
Copy link

sorear commented Apr 24, 2010

Here's a snippet of strace output after I accidentally ran parrot-nqp in a directory with a Regex.pbc file:

stat64("./Regex.pbc", {st_mode=S_IFREG|0644, st_size=100432, ...}) = 0
open("./Regex.pbc", O_RDONLY|O_LARGEFILE) = 3
stat64("./P6object.pbc", 0xbf9ee9bc)    = -1 ENOENT (No such file or directory)
stat64("./P6object.pir", 0xbf9ee9bc)    = -1 ENOENT (No such file or directory)
stat64("./P6object.pasm", 0xbf9ee9bc)   = -1 ENOENT (No such file or directory)
stat64("./P6object.pbc", 0xbf9ee9bc)    = -1 ENOENT (No such file or directory)
stat64("/usr/local/./P6object.pbc", 0xbf9ee9bc) = -1 ENOENT (No such file or directory)
stat64("/usr/local/./P6object.pir", 0xbf9ee9bc) = -1 ENOENT (No such file or directory)
stat64("/usr/local/./P6object.pasm", 0xbf9ee9bc) = -1 ENOENT (No such file or directory)
stat64("/usr/local/./P6object.pbc", 0xbf9ee9bc) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/parrot/2.3.0-devel/library/P6object.pbc", {st_mode=S_IFREG|0644, st_size=18448, ...}) = 0
stat64("/usr/local/lib/parrot/2.3.0-devel/library/P6object.pbc", {st_mode=S_IFREG|0644, st_size=18448, ...}) = 0
stat64("/usr/local/lib/parrot/2.3.0-devel/library/P6object.pbc", {st_mode=S_IFREG|0644, st_size=18448, ...}) = 0
stat64("/usr/local/lib/parrot/2.3.0-devel/library/P6object.pbc", {st_mode=S_IFREG|0644, st_size=18448, ...}) = 0
open("/usr/local/lib/parrot/2.3.0-devel/library/P6object.pbc", O_RDONLY|O_LARGEFILE) = 3

Parrot has taken Regex.pbc in the current directory before even checking for it in the standard libraries. The same behavior occurs with all other Parrot-based programs which use installed libraries. This provides an attack vector against Parrot users:

  1. Wait for Perl6-on-Parrot to hit the big time.
  2. Distribute a shady tarball containing a malicious P6Regex.pbc inside it.
  3. The victim unpacks the tarball and attempts to analyze the contents.
  4. The user runs his Perl 6 based editor.
  5. Rakudo loads Perl6.pbc from the current directory. My code is now running.

It's probably best to follow Perl 5's example here:

$ perl -V
...
  @INC:
    /usr/local/lib/perl5/site_perl/5.12.0/i686-linux-thread-multi
    /usr/local/lib/perl5/site_perl/5.12.0
    /usr/local/lib/perl5/5.12.0/i686-linux-thread-multi
    /usr/local/lib/perl5/5.12.0
    .

With the current directory at the end, installed programs which use only installed libraries will never be tricked into running code in the current directory. Hopefully it is not too common for installed programs to reference nonexistant libraries.

Originally http://trac.parrot.org/parrot/ticket/1589

@nwellnhof
Copy link
Member

The current directory should be completely removed from the search path. Putting the current directory at the end of the path doesn't help if an application tries to load a library that might not exist on every system. Windows made the same mistake:

 http://www.google.com/search?q=windows+dll+hijack+vulnerability

@jkeenan
Copy link
Contributor

jkeenan commented Sep 12, 2010

Can someone open up a branch and prepare a patch?

@parrot
Copy link
Collaborator

parrot commented Sep 12, 2010

There is a design decision about that? And a deprecation notice? The coding job is the minor part of the issue, IMO.

@jkeenan
Copy link
Contributor

jkeenan commented Mar 27, 2011

Replying to NotFound:

There is a design decision about that? And a deprecation notice? The coding job is the minor part of the issue, IMO.

cotto,

Could you evaluate the design decision (if any) to be made here?

Thanks.

kid51

@parrot
Copy link
Collaborator

parrot commented Mar 28, 2011

Design decision: pick one of the three:

1 - Keep the current way: look in current directory before library search paths. 2 - Look in curent directory only if no match found in library search paths. 3 - Look only in the library search paths.

@leto
Copy link
Member

leto commented Apr 1, 2011

I am +1 for #3, i.e. remove . from the default search path. This removes an entire class of security vulnerabilities. As long as we give a code snippet of how HLL authors can add . to the default search path, this shouldn't be a big issue.

@cotto
Copy link
Contributor

cotto commented Apr 2, 2011

Looking in the cwd as a last resort sounds like a sane default. +1.

@leto
Copy link
Member

leto commented Apr 6, 2011

Can we resolve this and make it part of 3.3 ? I think it is important. I am fine with putting . at the end of our search path.

@soh-cah-toa
Copy link
Contributor

I would like to take this ticket but, obviously, there is still no general consensus.

My opinion is that it should be removed all together from the search path. Placing the current working directory at the end of the search path does help protect against Trojans somewhat, but not completely.

@jkeenan
Copy link
Contributor

jkeenan commented Apr 21, 2011

Replying to soh_cah_toa:

soh_cah_toa,

Thanks for the submission.

But I have to ask: Are there any tests we should write to demonstrate what this patch does and that it does what we want it to?

I would be reluctant to apply it otherwise.

kid51

@soh-cah-toa
Copy link
Contributor

Yeah, cotto mentioned the same thing a few days ago.

Unfortunately, I'm still new to the whole unit testing thing and would need some guidance on that part.

I'll make it a point to talk to you guys about it tomorrow afternoon.

@soh-cah-toa
Copy link
Contributor

2245 byte attachment from soh-cah-toa
at http://trac.parrot.org/parrot/raw-attachment/ticket/1589/tt1589.patch

index 2bb9e13..b3758b9 100644
--- a/src/library.c
+++ b/src/library.c
@@ -155,8 +155,6 @@ parrot_init_library_paths(PARROT_INTERP)
         if (!STRING_IS_NULL(envvar) && !STRING_IS_EMPTY(envvar))
             VTABLE_push_string(interp, paths, envvar);
     }
-    entry = CONST_STRING(interp, "./");
-    VTABLE_push_string(interp, paths, entry);
  
   /\* define library paths */
   paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
  @@ -168,15 +166,11 @@ parrot_init_library_paths(PARROT_INTERP)
       if (!STRING_IS_NULL(envvar) && !STRING_IS_EMPTY(envvar))
           VTABLE_push_string(interp, paths, envvar);
   }
-    entry = CONST_STRING(interp, "./");
-    VTABLE_push_string(interp, paths, entry);
  
   /\* define languages paths */
   paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
   VTABLE_set_pmc_keyed_int(interp, lib_paths,
           PARROT_LIB_PATH_LANG, paths);
-    entry = CONST_STRING(interp, "./");
-    VTABLE_push_string(interp, paths, entry);
  
   /\* define dynext paths */
   paths = Parrot_pmc_new(interp, enum_class_ResizableStringArray);
  diff --git a/t/library/lib_search_path.t b/t/library/lib_search_path.t
  new file mode 100644
  index 0000000..62c3cca
  --- /dev/null
  +++ b/t/library/lib_search_path.t
  @@ -0,0 +1,43 @@
  +#!./parrot
  +# Copyright (C) 2011 Parrot Foundation.
  +
  +=head1 NAME
  +
  +t/library/lib_search_path.t - testing for proper search path precedence
  +
  +=head1 SYNOPSIS
  +
  +This test program verifies that Parrot searches for libraries in the
  +proper order.
  +
  +=head1 AUTHOR
  +
  +Kevin Polulak (a.k.a. soh_cah_toa) kpolulak@gmail.com
  +
  +=cut
  +
  +.const string TESTS = 2
  +
  +.sub 'main' :main
-    .include 'test_more.pir'
  +
-    .local pmc lib
-    .local pmc lib_cwd
  +
-    plan(TESTS)
  +
-    # Verify current working directory isn't searched
-    lib_cwd = loadlib 'lib_search_path.t'
-    is(lib_cwd, '', 'Verify current working directory not searched')
  +
-    # Verify runtime/parrot/dynext is searched
-   lib = loadlib 'osutils.pir'
-    isnt(lib, '', 'Verify runtime/parrot/dynext is searched')
  +.end
  +
  +# Local Variables:
  +#   mode: pir
  +#   fill-column: 100
  +# End:
  +# vim: expandtab shiftwidth=4 ft=pir:
  +

@soh-cah-toa
Copy link
Contributor

Patch incudes both the changes and tests.

@leto
Copy link
Member

leto commented May 4, 2011

Patch applied in  https://github.com/parrot/parrot/tree/tt1589_library_path

Deprecation data, wiki pages and possibly some docs still need to get modified.

@jkeenan
Copy link
Contributor

jkeenan commented May 22, 2011

Replying to dukeleto:

Patch applied in  https://github.com/parrot/parrot/tree/tt1589_library_path Deprecation data, wiki pages and possibly some docs still need to get modified.

dukeleto, soh_cah_toa:

Which of you can take care of those items?

Thank you very much.

kid51

@jkeenan
Copy link
Contributor

jkeenan commented Jun 11, 2011

Replying to jkeenan:

Replying to dukeleto:

Patch applied in  https://github.com/parrot/parrot/tree/tt1589_library_path Deprecation data, wiki pages and possibly some docs still need to get modified.

dukeleto, soh_cah_toa: Which of you can take care of those items?

Repeat question.

@ghost ghost assigned Whiteknight May 9, 2012
rurban pushed a commit that referenced this issue Dec 19, 2012
… paths

Add examples/pir/libpaths.pir to show the various deficiences of our current
library search paths.
Duplicates, installed paths mixed up with temp. build paths.
rurban pushed a commit that referenced this issue Dec 19, 2012
Currently tests 1-4 fails because of duplicates.
Only works on slash eq "/"
rurban pushed a commit that referenced this issue Dec 19, 2012
Works ok with the next commit to fix the duplicate
call to Parrot_lib_update_paths_from_config_hash.
rurban pushed a commit that referenced this issue Dec 19, 2012
Remove the duplicate call to Parrot_lib_update_paths_from_config_hash()
from Parrot_api_set_configuration_hash().

1.
  0  Parrot_lib_update_paths_from_config_hash (interp=0x412050) at src/library.c:214
  1  0x00007ffff7ab8d35 in Parrot_gbl_set_config_hash_interpreter (interp=0x412050) at src/global_setup.c:131
  2  0x00007ffff7ab8c54 in Parrot_set_config_hash_pmc (interp=0x412050, config=PMC<Hash> = {...}) at src/global_setup.c:98
  3  0x00007ffff7a99aca in Parrot_api_set_configuration_hash (interp_pmc=0x4dcb00, confighash=0x4e9a18) at src/embed/api.c:506
  4  0x0000000000402713 in Parrot_set_config_hash (interp_pmc=0x4dcb00) at src/parrot_config.c:3870
  5  0x000000000040175c in main (argc=2, argv=0x7fffffffe6b8) at frontend/parrot2/main.c:151
2.
  0  Parrot_lib_update_paths_from_config_hash (interp=0x412050) at src/library.c:214
  1  0x00007ffff7a99ad9 in Parrot_api_set_configuration_hash (interp_pmc=0x4dcb00, confighash=0x4e9a18) at src/embed/api.c:507
  2  0x0000000000402713 in Parrot_set_config_hash (interp_pmc=0x4dcb00) at src/parrot_config.c:3870
  3  0x000000000040175c in main (argc=2, argv=0x7fffffffe6b8) at frontend/parrot2/main.c:151

Parrot_set_config_hash_pmc already calls Parrot_lib_update_paths_from_config_hash, no need to
call it again.
rurban pushed a commit that referenced this issue Dec 19, 2012
rurban pushed a commit that referenced this issue Dec 26, 2012
… paths

Add examples/pir/libpaths.pir to show the various deficiences of our current
library search paths.
Duplicates, installed paths mixed up with temp. build paths.
rurban pushed a commit that referenced this issue Dec 26, 2012
Currently tests 1-4 fails because of duplicates.
Only works on slash eq "/"
rurban pushed a commit that referenced this issue Dec 26, 2012
Works ok with the next commit to fix the duplicate
call to Parrot_lib_update_paths_from_config_hash.
rurban pushed a commit that referenced this issue Dec 26, 2012
Remove the duplicate call to Parrot_lib_update_paths_from_config_hash()
from Parrot_api_set_configuration_hash().

1.
  0  Parrot_lib_update_paths_from_config_hash (interp=0x412050) at src/library.c:214
  1  0x00007ffff7ab8d35 in Parrot_gbl_set_config_hash_interpreter (interp=0x412050) at src/global_setup.c:131
  2  0x00007ffff7ab8c54 in Parrot_set_config_hash_pmc (interp=0x412050, config=PMC<Hash> = {...}) at src/global_setup.c:98
  3  0x00007ffff7a99aca in Parrot_api_set_configuration_hash (interp_pmc=0x4dcb00, confighash=0x4e9a18) at src/embed/api.c:506
  4  0x0000000000402713 in Parrot_set_config_hash (interp_pmc=0x4dcb00) at src/parrot_config.c:3870
  5  0x000000000040175c in main (argc=2, argv=0x7fffffffe6b8) at frontend/parrot2/main.c:151
2.
  0  Parrot_lib_update_paths_from_config_hash (interp=0x412050) at src/library.c:214
  1  0x00007ffff7a99ad9 in Parrot_api_set_configuration_hash (interp_pmc=0x4dcb00, confighash=0x4e9a18) at src/embed/api.c:507
  2  0x0000000000402713 in Parrot_set_config_hash (interp_pmc=0x4dcb00) at src/parrot_config.c:3870
  3  0x000000000040175c in main (argc=2, argv=0x7fffffffe6b8) at frontend/parrot2/main.c:151

Parrot_set_config_hash_pmc already calls Parrot_lib_update_paths_from_config_hash, no need to
call it again.
rurban pushed a commit that referenced this issue Dec 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants