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

pnfsmanager: avoid leaking whether or not file exists #6567

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,51 @@ public void setUploadSubDirectory(String path) {
_uploadSubDirectory = path;
}

private void checkLookupPermissions(Subject subject, List<FsInode> inodes, String path)
throws ChimeraFsException, CacheException {
for (FsInode inode : inodes) {
if (inode.isDirectory()) {
FileAttributes attributes = getFileAttributesForPermissionHandler(inode);
if (_permissionHandler.canLookup(subject, attributes) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied: " + path);
}
}
}
}

private List<FsInode> findDeepestParent(String path) throws ChimeraFsException {
FsPath target = FsPath.create(path);

do {
target = target.parent();
try {
return _fs.path2inodes(target.toString());
} catch (FileNotFoundChimeraFsException ignored) {
// Continue onto next parent.
}
} while (target != FsPath.ROOT);

throw new RuntimeException("Unable to find inode for ROOT");
}

private ExtendedInode pathToInode(Subject subject, String path)
throws ChimeraFsException, CacheException {
if (Subjects.isExemptFromNamespaceChecks(subject)) {
return new ExtendedInode(_fs, _fs.path2inode(path));
}

List<FsInode> inodes = _fs.path2inodes(path);
List<FsInode> inodes;
try {
inodes = _fs.path2inodes(path);
} catch (FileNotFoundChimeraFsException e) {
// Do not leak whether a file exists if user cannot 'cd' into the parent directory.
inodes = findDeepestParent(path);
checkLookupPermissions(subject, inodes, path);
throw e;
}

if (_verifyAllLookups) {
for (FsInode inode : inodes.subList(0, inodes.size() - 1)) {
if (inode.isDirectory()) {
FileAttributes attributes =
getFileAttributesForPermissionHandler(inode);
if (_permissionHandler.canLookup(subject, attributes) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Access denied: " + path);
}
}
}
checkLookupPermissions(subject, inodes.subList(0, inodes.size() - 1), path);
} else {
for (FsInode inode : Iterables.skip(Lists.reverse(inodes), 1)) {
if (inode.isDirectory()) {
Expand Down