vfs: Bind flock locks to file descriptors

* File locks created by flock should only apply for the file descriptor
  that was used to lock the file. Another fd on the same file should then
  be denied access (calling flock should fail).
* fcntl based locks, however, are in a separate namespace and are global
  to a team.
* This issue was found when running webkitpy test suite, and should close
  ticket #13795.
* Don't use session or team as comparison in release_advisory_lock(), as
  that information might not be available anymore (e.g. when called from
  Team::~Team()). This fixes #14121.

Change-Id: I9efb96cfcefe7e72b0060220c635a665e7e643cc
Co-authored-by: Axel Dörfler <[email protected]>
This commit is contained in:
Adrien Destugues
2018-05-22 20:29:21 +00:00
committed by Axel Dörfler
co-authored by Axel Dörfler
parent fc48586b9b
commit 8bca37d604
4 changed files with 75 additions and 44 deletions
+17 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006, Axel Dörfler, [email protected].
* Copyright 2002-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _FD_H
@@ -22,10 +22,13 @@ struct selectsync;
struct select_info;
struct fd_ops {
status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer, size_t *length);
status_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length);
status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer,
size_t *length);
status_t (*fd_write)(struct file_descriptor *, off_t pos,
const void *buffer, size_t *length);
off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType);
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length);
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer,
size_t length);
status_t (*fd_set_flags)(struct file_descriptor *, int flags);
status_t (*fd_select)(struct file_descriptor *, uint8 event,
struct selectsync *sync);
@@ -36,7 +39,8 @@ struct fd_ops {
size_t bufferSize, uint32 *_count);
status_t (*fd_rewind_dir)(struct file_descriptor *);
status_t (*fd_read_stat)(struct file_descriptor *, struct stat *);
status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *, int statMask);
status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *,
int statMask);
status_t (*fd_close)(struct file_descriptor *);
void (*fd_free)(struct file_descriptor *);
};
@@ -76,11 +80,13 @@ enum fd_types {
/* Prototypes */
extern struct file_descriptor *alloc_fd(void);
extern int new_fd_etc(struct io_context *, struct file_descriptor *, int firstIndex);
extern int new_fd_etc(struct io_context *, struct file_descriptor *,
int firstIndex);
extern int new_fd(struct io_context *, struct file_descriptor *);
extern struct file_descriptor *get_fd(struct io_context *, int);
extern struct file_descriptor *get_open_fd(struct io_context *, int);
extern void close_fd(struct file_descriptor *descriptor);
extern void close_fd(struct io_context *context,
struct file_descriptor *descriptor);
extern status_t close_fd_index(struct io_context *context, int fd);
extern void put_fd(struct file_descriptor *descriptor);
extern void disconnect_fd(struct file_descriptor *descriptor);
@@ -92,11 +98,13 @@ extern bool fd_is_valid(int fd, bool kernel);
extern struct vnode *fd_vnode(struct file_descriptor *descriptor);
extern bool fd_close_on_exec(struct io_context *context, int fd);
extern void fd_set_close_on_exec(struct io_context *context, int fd, bool closeFD);
extern void fd_set_close_on_exec(struct io_context *context, int fd,
bool closeFD);
static struct io_context *get_current_io_context(bool kernel);
extern status_t user_fd_kernel_ioctl(int fd, ulong op, void *buffer, size_t length);
extern status_t user_fd_kernel_ioctl(int fd, ulong op, void *buffer,
size_t length);
/* The prototypes of the (sys|user)_ functions are currently defined in vfs.h */
+3 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016, Axel Dörfler, [email protected].
* Copyright 2002-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -124,6 +124,8 @@ status_t vfs_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
bool kernel, char *path, size_t pathLength);
status_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID);
void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
status_t vfs_release_posix_lock(io_context* context,
struct file_descriptor* descriptor);
status_t vfs_unmount(dev_t mountID, uint32 flags);
status_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID);
status_t vfs_resolve_parent(struct vnode* parent, dev_t* device,