mirror of https://gitee.com/openkylin/linux.git
CIFS: Do not permit write to a range mandatory locked with a read lock
We don't need to permit a write to the area locked with a read lock by any process including the process that issues the write. Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Steve French <smfrench@gmail.com>
This commit is contained in:
parent
eb1b3fa5cd
commit
081c0414dc
|
@ -186,7 +186,7 @@ extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon);
|
||||||
extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
|
extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
|
||||||
__u64 length, __u8 type,
|
__u64 length, __u8 type,
|
||||||
struct cifsLockInfo **conf_lock,
|
struct cifsLockInfo **conf_lock,
|
||||||
bool rw_check);
|
int rw_check);
|
||||||
extern void cifs_add_pending_open(struct cifs_fid *fid,
|
extern void cifs_add_pending_open(struct cifs_fid *fid,
|
||||||
struct tcon_link *tlink,
|
struct tcon_link *tlink,
|
||||||
struct cifs_pending_open *open);
|
struct cifs_pending_open *open);
|
||||||
|
|
|
@ -759,10 +759,15 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CIFS_LOCK_OP 0
|
||||||
|
#define CIFS_READ_OP 1
|
||||||
|
#define CIFS_WRITE_OP 2
|
||||||
|
|
||||||
|
/* @rw_check : 0 - no op, 1 - read, 2 - write */
|
||||||
static bool
|
static bool
|
||||||
cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
|
cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
|
||||||
__u64 length, __u8 type, struct cifsFileInfo *cfile,
|
__u64 length, __u8 type, struct cifsFileInfo *cfile,
|
||||||
struct cifsLockInfo **conf_lock, bool rw_check)
|
struct cifsLockInfo **conf_lock, int rw_check)
|
||||||
{
|
{
|
||||||
struct cifsLockInfo *li;
|
struct cifsLockInfo *li;
|
||||||
struct cifsFileInfo *cur_cfile = fdlocks->cfile;
|
struct cifsFileInfo *cur_cfile = fdlocks->cfile;
|
||||||
|
@ -772,9 +777,13 @@ cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
|
||||||
if (offset + length <= li->offset ||
|
if (offset + length <= li->offset ||
|
||||||
offset >= li->offset + li->length)
|
offset >= li->offset + li->length)
|
||||||
continue;
|
continue;
|
||||||
if (rw_check && server->ops->compare_fids(cfile, cur_cfile) &&
|
if (rw_check != CIFS_LOCK_OP && current->tgid == li->pid &&
|
||||||
current->tgid == li->pid)
|
server->ops->compare_fids(cfile, cur_cfile)) {
|
||||||
continue;
|
/* shared lock prevents write op through the same fid */
|
||||||
|
if (!(li->type & server->vals->shared_lock_type) ||
|
||||||
|
rw_check != CIFS_WRITE_OP)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ((type & server->vals->shared_lock_type) &&
|
if ((type & server->vals->shared_lock_type) &&
|
||||||
((server->ops->compare_fids(cfile, cur_cfile) &&
|
((server->ops->compare_fids(cfile, cur_cfile) &&
|
||||||
current->tgid == li->pid) || type == li->type))
|
current->tgid == li->pid) || type == li->type))
|
||||||
|
@ -789,7 +798,7 @@ cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
|
||||||
bool
|
bool
|
||||||
cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
|
cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
|
||||||
__u8 type, struct cifsLockInfo **conf_lock,
|
__u8 type, struct cifsLockInfo **conf_lock,
|
||||||
bool rw_check)
|
int rw_check)
|
||||||
{
|
{
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
struct cifs_fid_locks *cur;
|
struct cifs_fid_locks *cur;
|
||||||
|
@ -825,7 +834,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
|
||||||
down_read(&cinode->lock_sem);
|
down_read(&cinode->lock_sem);
|
||||||
|
|
||||||
exist = cifs_find_lock_conflict(cfile, offset, length, type,
|
exist = cifs_find_lock_conflict(cfile, offset, length, type,
|
||||||
&conf_lock, false);
|
&conf_lock, CIFS_LOCK_OP);
|
||||||
if (exist) {
|
if (exist) {
|
||||||
flock->fl_start = conf_lock->offset;
|
flock->fl_start = conf_lock->offset;
|
||||||
flock->fl_end = conf_lock->offset + conf_lock->length - 1;
|
flock->fl_end = conf_lock->offset + conf_lock->length - 1;
|
||||||
|
@ -872,7 +881,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
|
||||||
down_write(&cinode->lock_sem);
|
down_write(&cinode->lock_sem);
|
||||||
|
|
||||||
exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
|
exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
|
||||||
lock->type, &conf_lock, false);
|
lock->type, &conf_lock, CIFS_LOCK_OP);
|
||||||
if (!exist && cinode->can_cache_brlcks) {
|
if (!exist && cinode->can_cache_brlcks) {
|
||||||
list_add_tail(&lock->llist, &cfile->llist->locks);
|
list_add_tail(&lock->llist, &cfile->llist->locks);
|
||||||
up_write(&cinode->lock_sem);
|
up_write(&cinode->lock_sem);
|
||||||
|
@ -2466,7 +2475,7 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov,
|
||||||
down_read(&cinode->lock_sem);
|
down_read(&cinode->lock_sem);
|
||||||
if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
|
if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
|
||||||
server->vals->exclusive_lock_type, NULL,
|
server->vals->exclusive_lock_type, NULL,
|
||||||
true)) {
|
CIFS_WRITE_OP)) {
|
||||||
mutex_lock(&inode->i_mutex);
|
mutex_lock(&inode->i_mutex);
|
||||||
rc = __generic_file_aio_write(iocb, iov, nr_segs,
|
rc = __generic_file_aio_write(iocb, iov, nr_segs,
|
||||||
&iocb->ki_pos);
|
&iocb->ki_pos);
|
||||||
|
@ -2901,7 +2910,7 @@ cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov,
|
||||||
down_read(&cinode->lock_sem);
|
down_read(&cinode->lock_sem);
|
||||||
if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
|
if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
|
||||||
tcon->ses->server->vals->shared_lock_type,
|
tcon->ses->server->vals->shared_lock_type,
|
||||||
NULL, true))
|
NULL, CIFS_READ_OP))
|
||||||
rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
|
rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
|
||||||
up_read(&cinode->lock_sem);
|
up_read(&cinode->lock_sem);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue