9p: Add refcount to p9_req_t
To avoid use-after-free(s), use a refcount to keep track of the usable references to any instantiated struct p9_req_t. This commit adds p9_req_put(), p9_req_get() and p9_req_try_get() as wrappers to kref_put(), kref_get() and kref_get_unless_zero(). These are used by the client and the transports to keep track of valid requests' references. p9_free_req() is added back and used as callback by kref_put(). Add SLAB_TYPESAFE_BY_RCU as it ensures that the memory freed by kmem_cache_free() will not be reused for another type until the rcu synchronisation period is over, so an address gotten under rcu read lock is safe to inc_ref() without corrupting random memory while the lock is held. Link: http://lkml.kernel.org/r/1535626341-20693-1-git-send-email-asmadeus@codewreck.org Co-developed-by: Dominique Martinet <dominique.martinet@cea.fr> Signed-off-by: Tomas Bortoli <tomasbortoli@gmail.com> Reported-by: syzbot+467050c1ce275af2a5b8@syzkaller.appspotmail.com Signed-off-by: Dominique Martinet <dominique.martinet@cea.fr>
This commit is contained in:

committed by
Dominique Martinet

parent
43cbcbee99
commit
728356dede
@@ -94,6 +94,7 @@ enum p9_req_status_t {
|
||||
struct p9_req_t {
|
||||
int status;
|
||||
int t_err;
|
||||
struct kref refcount;
|
||||
wait_queue_head_t wq;
|
||||
struct p9_fcall tc;
|
||||
struct p9_fcall rc;
|
||||
@@ -233,6 +234,19 @@ int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status);
|
||||
int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *fl);
|
||||
void p9_fcall_fini(struct p9_fcall *fc);
|
||||
struct p9_req_t *p9_tag_lookup(struct p9_client *, u16);
|
||||
|
||||
static inline void p9_req_get(struct p9_req_t *r)
|
||||
{
|
||||
kref_get(&r->refcount);
|
||||
}
|
||||
|
||||
static inline int p9_req_try_get(struct p9_req_t *r)
|
||||
{
|
||||
return kref_get_unless_zero(&r->refcount);
|
||||
}
|
||||
|
||||
int p9_req_put(struct p9_req_t *r);
|
||||
|
||||
void p9_client_cb(struct p9_client *c, struct p9_req_t *req, int status);
|
||||
|
||||
int p9_parse_header(struct p9_fcall *, int32_t *, int8_t *, int16_t *, int);
|
||||
|
Reference in New Issue
Block a user