Skip to content

Commit 4f8703f

Browse files
Zizhi Wobrauner
authored andcommitted
cachefiles: Set object to close if ondemand_id < 0 in copen
If copen is maliciously called in the user mode, it may delete the request corresponding to the random id. And the request may have not been read yet. Note that when the object is set to reopen, the open request will be done with the still reopen state in above case. As a result, the request corresponding to this object is always skipped in select_req function, so the read request is never completed and blocks other process. Fix this issue by simply set object to close if its id < 0 in copen. Signed-off-by: Zizhi Wo <[email protected]> Signed-off-by: Baokun Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Jeff Layton <[email protected]> Reviewed-by: Jia Zhu <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 4b4391e commit 4f8703f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/cachefiles/ondemand.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
182182
xas_store(&xas, NULL);
183183
xa_unlock(&cache->reqs);
184184

185+
info = req->object->ondemand;
185186
/* fail OPEN request if copen format is invalid */
186187
ret = kstrtol(psize, 0, &size);
187188
if (ret) {
@@ -201,7 +202,6 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
201202
goto out;
202203
}
203204

204-
info = req->object->ondemand;
205205
spin_lock(&info->lock);
206206
/*
207207
* The anonymous fd was closed before copen ? Fail the request.
@@ -241,6 +241,11 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args)
241241
wake_up_all(&cache->daemon_pollwq);
242242

243243
out:
244+
spin_lock(&info->lock);
245+
/* Need to set object close to avoid reopen status continuing */
246+
if (info->ondemand_id == CACHEFILES_ONDEMAND_ID_CLOSED)
247+
cachefiles_ondemand_set_object_close(req->object);
248+
spin_unlock(&info->lock);
244249
complete(&req->done);
245250
return ret;
246251
}

0 commit comments

Comments
 (0)