gramineproject / graphene

Graphene / Graphene-SGX - a library OS for Linux multi-process applications, with Intel SGX support
https://grapheneproject.io
GNU Lesser General Public License v3.0
771 stars 260 forks source link

Opening dir should fail with EISDIR but gets opened successfully #2550

Closed anjalirai-intel closed 3 years ago

anjalirai-intel commented 3 years ago

Description of the problem

  1. Opening device special file with O_RDONLY or O_WRONLY or O_RDWR permission fails
  2. Opening a symlink dir with O_RDONLY | O_CREAT should fails with error EISDIR but got SUCCESS
  3. Opening a dir with O_RDONLY | O_CREAT should also fail with EISDIR error but got success

Steps to reproduce

Execute attached files open11_setup in linux environment and open11_run with graphene-direct $ ./open11_setup $ graphene-direct ./open11_run

Expected results

TINFO: Timeout per run is 0h 05m 00s
TPASS: Open regular file O_RDONLY
TPASS: Open regular file O_WRONLY
TPASS: Open regular file O_RDWR
TPASS: Open regular file O_RDWR | O_SYNC
TPASS: Open regular file O_RDWR | O_TRUNC
TPASS: Open dir O_RDONLY
TPASS: Open dir O_RDWR, expect EISDIR
TPASS: Open regular file O_DIRECTORY, expect ENOTDIR
TPASS: Open hard link file O_RDONLY
TPASS: Open hard link file O_WRONLY
TPASS: Open hard link file O_RDWR
TPASS: Open sym link file O_RDONLY
TPASS: Open sym link file O_WRONLY
TPASS: Open sym link file O_RDWR
TPASS: Open sym link dir O_RDONLY
TPASS: Open sym link dir O_WRONLY, expect EISDIR
TPASS: Open sym link dir O_RDWR, expect EISDIR
TPASS: Open device special file O_RDONLY
TPASS: Open device special file O_WRONLY
TPASS: Open device special file O_RDWR
TPASS: Open non-existing regular file in existing dir
TPASS: Open link file O_RDONLY | O_CREAT
TPASS: Open symlink file O_RDONLY | O_CREAT
TPASS: Open regular file O_RDONLY | O_CREAT
TPASS: Open symlink dir O_RDONLY | O_CREAT, expect EISDIR
TPASS: Open dir O_RDONLY | O_CREAT, expect EISDIR
TPASS: Open regular file O_RDONLY | O_TRUNC, behaviour is undefined but should not oops or hang
TPASS: Open regular file(non-empty) O_RDONLY | O_TRUNC, behaviour is undefined but should not oops or hang

Summary:
passed   28
failed   0
skipped  0
warnings 0

Actual results

TINFO: Timeout per run is 0h 05m 00s
TPASS: Open regular file O_RDONLY
TPASS: Open regular file O_WRONLY
TPASS: Open regular file O_RDWR
TPASS: Open regular file O_RDWR | O_SYNC
TPASS: Open regular file O_RDWR | O_TRUNC
TPASS: Open dir O_RDONLY
TPASS: Open dir O_RDWR, expect EISDIR
TPASS: Open regular file O_DIRECTORY, expect ENOTDIR
TPASS: Open hard link file O_RDONLY
TPASS: Open hard link file O_WRONLY
TPASS: Open hard link file O_RDWR
TPASS: Open symlink file O_RDONLY
TPASS: Open symlink file O_WRONLY
TPASS: Open symlink file O_RDWR
TPASS: Open symlink dir O_RDONLY
TPASS: Open symlink dir O_WRONLY, expect EISDIR
TPASS: Open sym link dir O_RDWR, expect EISDIR

> TFAIL: Open device special file O_RDONLY - expected SUCCESS: EACCES (13)
> TFAIL: Open device special file O_WRONLY - expected SUCCESS: EACCES (13)
> TFAIL: Open device special file O_RDWR - expected SUCCESS: EACCES (13)

TPASS: Open non-existing regular file in existing dir
TPASS: Open link file O_RDONLY | O_CREAT
TPASS: Open symlink file O_RDONLY | O_CREAT
TPASS: Open regular file O_RDONLY | O_CREAT

> TFAIL: Open symlink dir O_RDONLY | O_CREAT, expect EISDIR - expected EISDIR: SUCCESS (0)
> TFAIL: Open dir O_RDONLY | O_CREAT, expect EISDIR - expected EISDIR: SUCCESS (0)

TPASS: Open regular file O_RDONLY | O_TRUNC, behaviour is undefined but should not oops or hang
TPASS: Open regular file(non-empty) O_RDONLY | O_TRUNC, behaviour is undefined but should not oops or hang

Summary:
passed   23
failed   5
skipped  0
warnings 0

open11.zip

Satya1493 commented 3 years ago

@dimakuv please assign this to me.

sahason commented 3 years ago

The first issue in the list ‘Opening device special file with O_RDONLY or O_WRONLY or O_RDWR permission fails’ is expected behaviour in graphene. As the permissions on the host of this device special file are 000, opening the file is not allowed in graphene. The reason behind the test to pass in host is running as super user.