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

8324811: java/nio/file/Files/CopyMoveVariations.java fails run with non-root user and /tmp and -w JTwork are in different partitions #17606

Closed
wants to merge 1 commit into from

Conversation

sendaoYan
Copy link
Member

@sendaoYan sendaoYan commented Jan 28, 2024


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8324811: java/nio/file/Files/CopyMoveVariations.java fails run with non-root user (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17606/head:pull/17606
$ git checkout pull/17606

Update a local copy of the PR:
$ git checkout pull/17606
$ git pull https://git.openjdk.org/jdk.git pull/17606/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17606

View PR using the GUI difftool:
$ git pr show -t 17606

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17606.diff

Webrev

Link to Webrev Comment

…hen run with non-root user

Signed-off-by: sendaoYan <yansendao.ysd@alibaba-inc.com>
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 28, 2024

👋 Welcome back syan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 28, 2024

@sendaoYan The following label will be automatically applied to this pull request:

  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added nio nio-dev@openjdk.org rfr Pull request is ready for review labels Jan 28, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 28, 2024

Webrevs

@sendaoYan
Copy link
Member Author

sendaoYan commented Jan 28, 2024

Before this PR, this testcase run fail with non-root user. Obviously the testcase author run this testcase with root user or privilege users. I think it's necessary to make tests run pass with non-root users.

When run this test case with root user, it will not cause java.nio.file.AccessDeniedException in any cases, do the test case bug will not expose.

Before the patch apply, the testcase run fail with non-root user:

image

After the patch apply, the testcase run pass with non-root user:

image

@sendaoYan sendaoYan changed the title 8322881: [TESTBUG]java/nio/file/Files/CopyMoveVariations.java fails when run with non-root user 8322881: [TESTBUG]java/nio/file/Files/CopyMoveVariations.java fails with AccessDeniedException due to permissions of files in /tmp Jan 28, 2024
@sendaoYan sendaoYan changed the title 8322881: [TESTBUG]java/nio/file/Files/CopyMoveVariations.java fails with AccessDeniedException due to permissions of files in /tmp 8322881: java/nio/file/Files/CopyMoveVariations.java fails with AccessDeniedException due to permissions of files in /tmp Jan 28, 2024
@sendaoYan sendaoYan changed the title 8322881: java/nio/file/Files/CopyMoveVariations.java fails with AccessDeniedException due to permissions of files in /tmp 8324811: [TESTBUG]java/nio/file/Files/CopyMoveVariations.java fails run with non-root user Jan 29, 2024
@sendaoYan sendaoYan changed the title 8324811: [TESTBUG]java/nio/file/Files/CopyMoveVariations.java fails run with non-root user 8324811: java/nio/file/Files/CopyMoveVariations.java fails run with non-root user Jan 30, 2024
@sendaoYan
Copy link
Member Author

This PR only change the testcase, the testcase change has been verified. Please review this PR.

@AlanBateman
Copy link
Contributor

This PR only change the testcase, the testcase change has been verified. Please review this PR.

@bplb Did you ever run into this? I don't run the tests with root access and haven't seen this. The current changes in pull/17235 aren't complete but if that change goes in then the test won't be testing /tmp.

@bplb
Copy link
Member

bplb commented Feb 21, 2024

@bplb Did you ever run into this? I don't run the tests with root access and haven't seen this. The current changes in pull/17235 aren't complete but if that change goes in then the test won't be testing /tmp.

@AlanBateman No, I have not seen this behavior, nor that addressed in #17235 for that matter. I think that if issue JDK-8324811 is not reproducible after #17235, then the present PR and its associated issue can be closed.

@sendaoYan
Copy link
Member Author

sendaoYan commented Feb 22, 2024

This PR only change the testcase, the testcase change has been verified. Please review this PR.

@bplb Did you ever run into this? I don't run the tests with root access and haven't seen this. The current changes in pull/17235 aren't complete but if that change goes in then the test won't be testing /tmp.

Only the jtreg work directory and the /tmp on the different disk partition can replay this failure.

image

The first jtreg test, the jtreg work directory is in /dev/vda3(mount on /), and the tmp is in /dev/loop0(mount on /tmp), so this test run fail.
The second jtreg test, use -w options make jtreg directory point the same to /tmp, then this test run success.

It's the commands to make /tmp diffrent partition from /

sudo dd if=/dev/zero of=/home/tmp-file bs=1 count=0 seek=50G
sudo mkfs.ext4 /home/tmp-file
sudo mount /home/tmp-file /tmp
sudo chmod a=rwx,u+t /tmp

@sendaoYan
Copy link
Member Author

sendaoYan commented Feb 22, 2024

@bplb Did you ever run into this? I don't run the tests with root access and haven't seen this. The current changes in pull/17235 aren't complete but if that change goes in then the test won't be testing /tmp.

@AlanBateman No, I have not seen this behavior, nor that addressed in #17235 for that matter. I think that if issue JDK-8324811 is not reproducible after #17235, then the present PR and its associated issue can be closed.

This testcase include 3 Files.move(source, target, options operations(line 195, line 212, line 232), only the line 195 miss try catch AccessDeniedException surround.
And for the line 219, when there is a AccessDeniedException, then the source file should miss read permission, so mode.charAt(1) != 'r' , rather than mode.charAt(1) != 'w'.
So, it seems that it's a testcase bug cause this testcase run fail at some situation.
Maybe this PR is more reasonable than #17235

@bplb
Copy link
Member

bplb commented Feb 22, 2024

Obviously the testcase author run this testcase with root user or privilege users.

How could this conjecture be obvious?

I am the author of this test and I never run tests under anything but my own login, and certainly not as root or any other privileged user.

@bplb
Copy link
Member

bplb commented Feb 22, 2024

This testcase include 3 Files.move(source, target, options operations(line 195, line 212, line 232), only the line 195 miss try catch AccessDeniedException surround.

This is because AccessDeniedException is not expected. For a file move operation there is no permission requirement unless the source is a directory, in which case it must be writable.

And for the line 219, when there is a AccessDeniedException, then the source file should miss read permission, so mode.charAt(1) != 'r' , rather than mode.charAt(1) != 'w'.

The modes are defined by

 99             String[] modes = new String[] {
100                 "---------", "r--r--r--", "-w--w--w-", "rw-rw-rw-"
101             };

so I do not see how mode.charAt(1) could ever return r. Anyway, as a directory and not a file is being moved, the requirement is that the source directory be wrotable so w is correct.

So, it seems that it's a testcase bug cause this testcase run fail at some situation.

As previously mentioned, we have not seen this in any reasonable scenario.

Maybe this PR is more reasonable than #17235

Actually I think #17235 is more reasonable and that this PR should be withdrawn.

@sendaoYan
Copy link
Member Author

sendaoYan commented Feb 23, 2024

Obviously the testcase author run this testcase with root user or privilege users.

How could this conjecture be obvious?

I am the author of this test and I never run tests under anything but my own login, and certainly not as root or any other privileged user.

Only the jtreg work directory and the /tmp on the different disk partitions can replay this fail. As I descripte #17606 (comment).
If the jtreg work directory and the /tmp on the different disk, but run with root privilege, the failure also can not replay.

There are two conditions Indispensable to replay the test failure:

  1. run with non-privilege user.
  2. the jtreg work directory(set by -w options, default is relative JTwork) and the /tmp os on the different disk partition descripte as above.

So, if you run with non-root privilege previous, Maybe your /tmp and JTwork are on the same disk partition.

@sendaoYan
Copy link
Member Author

This testcase include 3 Files.move(source, target, options operations(line 195, line 212, line 232), only the line 195 miss try catch AccessDeniedException surround.

This is because AccessDeniedException is not expected. For a file move operation there is no permission requirement unless the source is a directory, in which case it must be writable.

And for the line 219, when there is a AccessDeniedException, then the source file should miss read permission, so mode.charAt(1) != 'r' , rather than mode.charAt(1) != 'w'.

The modes are defined by

 99             String[] modes = new String[] {
100                 "---------", "r--r--r--", "-w--w--w-", "rw-rw-rw-"
101             };

so I do not see how mode.charAt(1) could ever return r. Anyway, as a directory and not a file is being moved, the requirement is that the source directory be wrotable so w is correct.

So, it seems that it's a testcase bug cause this testcase run fail at some situation.

As previously mentioned, we have not seen this in any reasonable scenario.

Maybe this PR is more reasonable than #17235

Actually I think #17235 is more reasonable and that this PR should be withdrawn.

In the Linux operating system environment, the file operation permissions may be different if the source and target are in different partitions and if the source and target are in the same partition. I am not professional in this area, so this PR is closed.

@sendaoYan sendaoYan closed this Feb 23, 2024
@sendaoYan sendaoYan changed the title 8324811: java/nio/file/Files/CopyMoveVariations.java fails run with non-root user 8324811: java/nio/file/Files/CopyMoveVariations.java fails run with non-root user and /tmp and -w JTwork are in different partitions Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nio nio-dev@openjdk.org rfr Pull request is ready for review
3 participants