* [PATCH] patch.bbclass: increase security
@ 2012-09-14 13:12 Constantin Musca
2012-09-14 14:18 ` Enrico Scholz
0 siblings, 1 reply; 3+ messages in thread
From: Constantin Musca @ 2012-09-14 13:12 UTC (permalink / raw)
To: openembedded-core; +Cc: Constantin Musca
- Use mkdtemp for generating temp dir names
- Use bb.utils.remove for removing temp dirs
- Add comment for explaining the "patch" workaround
Signed-off-by: Constantin Musca <constantinx.musca@intel.com>
---
meta/classes/patch.bbclass | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index d010438..4b535d9 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -139,10 +139,14 @@ python patch_do_patch() {
path = os.getenv('PATH')
os.putenv('PATH', d.getVar('PATH', True))
- import shutil
- process_tmpdir = os.path.join('/tmp', str(os.getpid()))
+ # We must use one TMPDIR per process (/tmp/${PID}${random_chars})
+ # so that the "patch" processes don't generate the same temp
+ # file name.
+
+ import tempfile
+ process_tmpdir = tempfile.mkdtemp(prefix=str(os.getpid()))
if os.path.exists(process_tmpdir):
- shutil.rmtree(process_tmpdir)
+ bb.utils.remove(process_tmpdir, True)
os.makedirs(process_tmpdir)
os.environ['TMPDIR'] = process_tmpdir
@@ -168,15 +172,15 @@ python patch_do_patch() {
try:
patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
except Exception as exc:
- shutil.rmtree(process_tmpdir)
+ bb.utils.remove(process_tmpdir, True)
bb.fatal(str(exc))
try:
resolver.Resolve()
except bb.BBHandledException as e:
- shutil.rmtree(process_tmpdir)
+ bb.utils.remove(process_tmpdir, True)
bb.fatal(str(e))
- shutil.rmtree(process_tmpdir)
+ bb.utils.remove(process_tmpdir, True)
}
patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] patch.bbclass: increase security
2012-09-14 13:12 [PATCH] patch.bbclass: increase security Constantin Musca
@ 2012-09-14 14:18 ` Enrico Scholz
2012-09-14 13:51 ` Constantin Musca
0 siblings, 1 reply; 3+ messages in thread
From: Enrico Scholz @ 2012-09-14 14:18 UTC (permalink / raw)
To: openembedded-core; +Cc: Constantin Musca
Constantin Musca
<constantinx.musca-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> writes:
> + process_tmpdir = tempfile.mkdtemp(prefix=str(os.getpid()))
fwiw, prefix is usually something which identifies the origin of the
tempfile. getpid() does not make much sense here; it might be better to
use something like 'bitbake-patch' or so.
> if os.path.exists(process_tmpdir):
this will trigger everytime becuase 'mkdtemp()' creates the directory.
> + bb.utils.remove(process_tmpdir, True)
this lowers the just gained security... :(
> os.makedirs(process_tmpdir)
not needed
---> a plain
| process_tmpdir = tempfile.mkdtemp()
| os.environ['TMPDIR'] = process_tmpdir
suffices (add a custom prefix when you really want it).
Enrico
--
SIGMA Chemnitz GmbH Registergericht: Amtsgericht Chemnitz HRB 1750
Am Erlenwald 13 Geschaeftsfuehrer: Grit Freitag, Frank Pyritz
09128 Chemnitz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] patch.bbclass: increase security
2012-09-14 14:18 ` Enrico Scholz
@ 2012-09-14 13:51 ` Constantin Musca
0 siblings, 0 replies; 3+ messages in thread
From: Constantin Musca @ 2012-09-14 13:51 UTC (permalink / raw)
To: Enrico Scholz; +Cc: Constantin Musca, openembedded-core
On 09/14/2012 05:18 PM, Enrico Scholz wrote:
>
> Constantin Musca
> <constantinx.musca-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> writes:
>
>> + process_tmpdir = tempfile.mkdtemp(prefix=str(os.getpid()))
> fwiw, prefix is usually something which identifies the origin of the
> tempfile. getpid() does not make much sense here; it might be better to
> use something like 'bitbake-patch' or so.
>
>
>> if os.path.exists(process_tmpdir):
> this will trigger everytime becuase 'mkdtemp()' creates the directory.
>
>> + bb.utils.remove(process_tmpdir, True)
> this lowers the just gained security... :(
>
>
>> os.makedirs(process_tmpdir)
> not needed
>
>
> ---> a plain
>
> | process_tmpdir = tempfile.mkdtemp()
> | os.environ['TMPDIR'] = process_tmpdir
>
> suffices (add a custom prefix when you really want it).
>
>
>
> Enrico
Is it ok now ? ([PATCH v2] patch.bbclass: increase security)
Constantin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-14 14:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14 13:12 [PATCH] patch.bbclass: increase security Constantin Musca
2012-09-14 14:18 ` Enrico Scholz
2012-09-14 13:51 ` Constantin Musca
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox