gramineproject / gramine

A library OS for Linux multi-process applications, with Intel SGX support
GNU Lesser General Public License v3.0
587 stars 193 forks source link

Dup2 syscall incorrectly reports EINVAL when oldfd and newfd are same #180

Closed jinengandhi-intel closed 2 years ago

jinengandhi-intel commented 2 years ago

Description of the problem

As per Linux man pages, dup2 does nothing and should return newfd and not EINVAL.

https://man7.org/linux/man-pages/man2/dup.2.html

In the upgraded LTP test, a new test validating this functionality was added which is failing with Gramine.

Link to new LTP test: https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/dup2/dup206.c

intel@intel-Ice-Lake-Client-Platform:~/graphene_newltp/LibOS/shim/test/ltp/install/testcases/bin$ gramine-direct dup206
[P1:T1:] error: Mounting file:/proc may expose unsanitized, unsafe files to unsuspecting application. Gramine will continue application execution, but this configuration is not recommended for use in production!
/home/intel/graphene_newltp/LibOS/shim/test/ltp/ltp_src/lib/tst_test.c:1362: TINFO: Timeout per run is 0h 05m 00s
/home/intel/graphene_newltp/LibOS/shim/test/ltp/ltp_src/testcases/kernel/syscalls/dup2/dup206.c:22: TFAIL: dup2(3, 3) failed: EINVAL (22)
/home/intel/graphene_newltp/LibOS/shim/test/ltp/ltp_src/testcases/kernel/syscalls/dup2/dup206.c:25: TFAIL: dup2(3, 3) returns wrong newfd(-1)
/home/intel/graphene_newltp/LibOS/shim/test/ltp/ltp_src/testcases/kernel/syscalls/dup2/dup206.c:26: TBROK: close(-1) failed: EBADF (9)

Steps to reproduce

Since the issues are seen with the LTP upgraded tests and something that we are still migrating to the local CI, follow the below steps to checkout and run the latest LTP test in your local workspace.

Checkout the local CI repo present here https://github.com/jinengandhi-intel/graphene_local_ci/tree/ltp_upgrade

cd gramine/LibOS/shim/test/ltp
cp -rf <ltp_upgrade_localci_branch>/ltp_src .
cp -rf <ltp_upgrade_localci_branch>ltp_config/* .

# To build the tests and generate manifest files
make -j8 -f Makefile.LTP all LTPCFG=ltp_tests.cfg LTPTESTFILE=./install/runtest/syscalls-new 

# To run the tests
cd install/testcases/bin/
gramine-direct dup206

Expected results

Actual results

dimakuv commented 2 years ago

This looks like a pretty trivial bug fix. Any volunteers to fix it? @vijaydhanraj @svenkata9 ?

svenkata9 commented 2 years ago

I'll take it up