Commit ec99f6d3 authored by Elena Reshetova's avatar Elena Reshetova Committed by Miklos Szeredi
Browse files

fuse: convert fuse_req.count from atomic_t to refcount_t



refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
Signed-off-by: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 4e8c2eb5
...@@ -45,7 +45,7 @@ static void fuse_request_init(struct fuse_req *req, struct page **pages, ...@@ -45,7 +45,7 @@ static void fuse_request_init(struct fuse_req *req, struct page **pages,
INIT_LIST_HEAD(&req->list); INIT_LIST_HEAD(&req->list);
INIT_LIST_HEAD(&req->intr_entry); INIT_LIST_HEAD(&req->intr_entry);
init_waitqueue_head(&req->waitq); init_waitqueue_head(&req->waitq);
atomic_set(&req->count, 1); refcount_set(&req->count, 1);
req->pages = pages; req->pages = pages;
req->page_descs = page_descs; req->page_descs = page_descs;
req->max_pages = npages; req->max_pages = npages;
...@@ -102,14 +102,13 @@ void fuse_request_free(struct fuse_req *req) ...@@ -102,14 +102,13 @@ void fuse_request_free(struct fuse_req *req)
void __fuse_get_request(struct fuse_req *req) void __fuse_get_request(struct fuse_req *req)
{ {
atomic_inc(&req->count); refcount_inc(&req->count);
} }
/* Must be called with > 1 refcount */ /* Must be called with > 1 refcount */
static void __fuse_put_request(struct fuse_req *req) static void __fuse_put_request(struct fuse_req *req)
{ {
BUG_ON(atomic_read(&req->count) < 2); refcount_dec(&req->count);
atomic_dec(&req->count);
} }
static void fuse_req_init_context(struct fuse_req *req) static void fuse_req_init_context(struct fuse_req *req)
...@@ -264,7 +263,7 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, ...@@ -264,7 +263,7 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
{ {
if (atomic_dec_and_test(&req->count)) { if (refcount_dec_and_test(&req->count)) {
if (test_bit(FR_BACKGROUND, &req->flags)) { if (test_bit(FR_BACKGROUND, &req->flags)) {
/* /*
* We get here in the unlikely case that a background * We get here in the unlikely case that a background
......
...@@ -307,7 +307,7 @@ struct fuse_req { ...@@ -307,7 +307,7 @@ struct fuse_req {
struct list_head intr_entry; struct list_head intr_entry;
/** refcount */ /** refcount */
atomic_t count; refcount_t count;
/** Unique ID for the interrupt request */ /** Unique ID for the interrupt request */
u64 intr_unique; u64 intr_unique;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment