nfs4: Enforce checking lock type against open mode
This commit is contained in:
@@ -650,9 +650,41 @@ Inode::WriteStat(const struct stat* st, uint32 mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline status_t
|
||||||
|
Inode::_CheckLockType(short ltype, uint32 mode)
|
||||||
|
{
|
||||||
|
switch (ltype) {
|
||||||
|
case F_UNLCK:
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
case F_RDLCK:
|
||||||
|
if ((mode & O_RDONLY) == 0 && (mode & O_RDWR) == 0)
|
||||||
|
return EBADF;
|
||||||
|
else
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
case F_WRLCK:
|
||||||
|
if ((mode & O_WRONLY) == 0 && (mode & O_RDWR) == 0)
|
||||||
|
return EBADF;
|
||||||
|
else
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
Inode::TestLock(OpenFileCookie* cookie, struct flock* lock)
|
Inode::TestLock(OpenFileCookie* cookie, struct flock* lock)
|
||||||
{
|
{
|
||||||
|
if (lock->l_type == F_UNLCK)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
status_t result = _CheckLockType(lock->l_type, cookie->fMode);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
RPC::Server* serv = fFilesystem->Server();
|
RPC::Server* serv = fFilesystem->Server();
|
||||||
Request request(serv);
|
Request request(serv);
|
||||||
@@ -693,6 +725,10 @@ status_t
|
|||||||
Inode::AcquireLock(OpenFileCookie* cookie, const struct flock* lock,
|
Inode::AcquireLock(OpenFileCookie* cookie, const struct flock* lock,
|
||||||
bool wait)
|
bool wait)
|
||||||
{
|
{
|
||||||
|
status_t result = _CheckLockType(lock->l_type, cookie->fMode);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
LockInfo* linfo = new LockInfo;
|
LockInfo* linfo = new LockInfo;
|
||||||
if (linfo == NULL)
|
if (linfo == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ protected:
|
|||||||
status_t _ReadDirUp(struct dirent* de, uint32 pos,
|
status_t _ReadDirUp(struct dirent* de, uint32 pos,
|
||||||
uint32 size);
|
uint32 size);
|
||||||
|
|
||||||
|
static inline status_t _CheckLockType(short ltype, uint32 mode);
|
||||||
|
|
||||||
static inline ino_t _FileIdToInoT(uint64 fileid);
|
static inline ino_t _FileIdToInoT(uint64 fileid);
|
||||||
|
|
||||||
uint64 fFileId;
|
uint64 fFileId;
|
||||||
|
|||||||
Reference in New Issue
Block a user