Re: [syzbot] KASAN: use-after-free Read in rdma_close
From: asmadeus@codewreck.org
Date: 2022-09-28 11:23:47
Also in:
lkml
Leon Romanovsky wrote on Wed, Sep 28, 2022 at 01:49:19PM +0300:
quoted
But I agree I did get that wrong: trans_mod->close() wasn't called if create failed. We do want the idr_for_each_entry() that is in p9_client_destroy so rather than revert the commit (fix a bug, create a new one..) I'd rather split it out in an internal function that takes a 'bool close' or something to not duplicate the rest. (Bit of a nitpick, sure)Please do proper unwind without extra variable. Proper unwind means that you will call to symmetrical functions in destroy as you used in create: alloc -> free create -> close e.t.c When you use some global function like you did, there is huge chance to see unwind bugs.
No. Duplicating complicated cleanup code leads to leaks like we used to have; that destroy function already frees up things in the right order. And, well, frankly 9p is a mess anyway; the problem here is that trans_mod->create() doesn't leave any trace we can rely on in a common cleanup function, but the original "proper unwind" missed: - p9_fid_destroy/tags cleanup for anything in the cache (because, yes, apparently fuzzers managed to use the client before it's fully initialized. I don't want to know.) - fcall cache destory I'm not duplicating all this mess. This is the only place that can call destroy before trans_mod create has been called, I wish we'd have a pattern like "clnt->trans = clnt->trans_mod->create()" so we could just check if trans is null, but a destroy parameter will do. ... Well, I guess it's not like there are out of tree trans, I could just change create() to do that if I had infinite time... -- Dominique