All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] runltp - error when using another tmp folder
@ 2018-05-02 14:22 =?unknown-8bit?q?Myl=C3=A8ne?= Josserand
  2018-05-02 15:46 ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: =?unknown-8bit?q?Myl=C3=A8ne?= Josserand @ 2018-05-02 14:22 UTC (permalink / raw)
  To: ltp

Hello everyone,

While testing some syscalls tests on an embedded device, I got an error
on many tests (running as "root" user).

Here is an output for chmod03 test:

tst_tmpdir: mkdtemp(/home/root/ltp-XXXXAeI13S/utirN7h1b) failed:
errno=EACCES(13): Permission denied

After looking at the code, Thomas (in CC) and myself found that the
"temp" folder that we used (with "-d" option on "runltp") does not have
a permission of 777.
According to the code of runltp, it seems that it creates a folder with
this permission but because it is retrieving the option using
"readlink", if the folder is not available, it leads to an error
because TMPBASE variable is empty:

BusyBox v1.24.1 (2018-02-10 17:35:25 CET) multi-call binary.

Usage: mkdir [OPTIONS] DIRECTORY...
FATAL: Unable to make temporary directory


Currently, we fixed the issue by using a /tmp folder that already has
777 permission (default's one) but maybe, other users may want to use
another folder and may have the same error we got.

Let me know if you have ideas on how we could improve it.
Thank you in advance.

Best regards,

Mylène

-- 
Mylène Josserand, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] runltp - error when using another tmp folder
  2018-05-02 14:22 [LTP] runltp - error when using another tmp folder =?unknown-8bit?q?Myl=C3=A8ne?= Josserand
@ 2018-05-02 15:46 ` Thomas Petazzoni
  2018-05-16  9:10   ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2018-05-02 15:46 UTC (permalink / raw)
  To: ltp

Hello,

On Wed, 2 May 2018 16:22:14 +0200, Mylène Josserand wrote:

> After looking at the code, Thomas (in CC) and myself found that the
> "temp" folder that we used (with "-d" option on "runltp") does not have
> a permission of 777.
> According to the code of runltp, it seems that it creates a folder with
> this permission but because it is retrieving the option using
> "readlink", if the folder is not available, it leads to an error
> because TMPBASE variable is empty:

Hum, I think the situation is a bit more complicated than that. The
runltp code goes like this:

            export TMPBASE=$(readlink -f ${OPTARG}) ;;
[...]

    # Added -m 777 for tests that call tst_tmpdir() and try to
    #  write to it as user nobody
    mkdir -m 777 -p $TMPBASE || \
    {
        echo "FATAL: Unable to make temporary directory $TMPBASE"
        exit 1
    }
    # use mktemp to create "safe" temporary directories
    export TMPTEMPLATE="${TMPBASE}/ltp-XXXXXXXXXX"
    TMP=`mktemp -d $TMPTEMPLATE` || \
    {
        echo "FATAL: Unable to make temporary directory: $TMP"
        exit 1
    }
    export TMP
    # To be invoked by tst_tmpdir()
    # write to it as user nobody
    export TMPDIR=$TMP

    chmod 777 $TMP || \
    {
      echo "unable to chmod 777 $TMP ... aborting"
      exit 1
    }

So you've got two possible situations:

 (1) TMPBASE is an already existing directory. In this case, the "-m
     777" argument in mkdir -m 777 -p $TMPBASE is useless because it is
     only used by mkdir when the directory to be created doesn't exist
     yet.

 (2) TMPBASE is not an existing directory. In this case, readlink will
     return an empty string, and mkdir will fail because TMPBASE is
     empty.

> Currently, we fixed the issue by using a /tmp folder that already has
> 777 permission (default's one) but maybe, other users may want to use
> another folder and may have the same error we got.

Now that I look at the code again, in the end, I don't understand why
the user nobody was not able to create its temporary files. Indeed,
TMPDIR which gets exported to tests, and is used by tst_tmpdir() is
defined as:

 TMPDIR = $TMPBASE/ltp-XXXXXXXXXX/

and this directory is chmod 777. So even if TMPBASE is only
root-writable, TMPDIR should be world-writable. So there's something we
misunderstood here.

That being said, that doesn't remove the bug on how TMPBASE is handled,
which is described above.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] runltp - error when using another tmp folder
  2018-05-02 15:46 ` Thomas Petazzoni
@ 2018-05-16  9:10   ` Cyril Hrubis
  0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2018-05-16  9:10 UTC (permalink / raw)
  To: ltp

Hi!
> Hum, I think the situation is a bit more complicated than that. The
> runltp code goes like this:
> 
>             export TMPBASE=$(readlink -f ${OPTARG}) ;;
> [...]
> 
>     # Added -m 777 for tests that call tst_tmpdir() and try to
>     #  write to it as user nobody
>     mkdir -m 777 -p $TMPBASE || \
>     {
>         echo "FATAL: Unable to make temporary directory $TMPBASE"
>         exit 1
>     }
>     # use mktemp to create "safe" temporary directories
>     export TMPTEMPLATE="${TMPBASE}/ltp-XXXXXXXXXX"
>     TMP=`mktemp -d $TMPTEMPLATE` || \
>     {
>         echo "FATAL: Unable to make temporary directory: $TMP"
>         exit 1
>     }
>     export TMP
>     # To be invoked by tst_tmpdir()
>     # write to it as user nobody
>     export TMPDIR=$TMP
> 
>     chmod 777 $TMP || \
>     {
>       echo "unable to chmod 777 $TMP ... aborting"
>       exit 1
>     }
> 
> So you've got two possible situations:
> 
>  (1) TMPBASE is an already existing directory. In this case, the "-m
>      777" argument in mkdir -m 777 -p $TMPBASE is useless because it is
>      only used by mkdir when the directory to be created doesn't exist
>      yet.
> 
>  (2) TMPBASE is not an existing directory. In this case, readlink will
>      return an empty string, and mkdir will fail because TMPBASE is
>      empty.

Actually you may pass a path with last nonexisting component and the
readlink -f will still work fine. Hence if you pass -d /tmp/nonexistent/
it will create the nonexistent directory with the mkdir there.

But that does not change the fact that runltp is user unfriendly with
it's options...

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-16  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 14:22 [LTP] runltp - error when using another tmp folder =?unknown-8bit?q?Myl=C3=A8ne?= Josserand
2018-05-02 15:46 ` Thomas Petazzoni
2018-05-16  9:10   ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.