linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Dominique Martinet <asmadeus@codewreck.org>
Cc: v9fs-developer@lists.sourceforge.net, linux_oss@crudebyte.com,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	syzbot+67d13108d855f451cafc@syzkaller.appspotmail.com
Subject: Re: [PATCH v3] 9p: client_create/destroy: only call trans_mod->close after create
Date: Thu, 29 Sep 2022 08:54:10 +0300	[thread overview]
Message-ID: <YzUzAqsq803Z+rtr@unreal> (raw)
In-Reply-To: <20220928221923.1751130-1-asmadeus@codewreck.org>

On Thu, Sep 29, 2022 at 07:19:23AM +0900, Dominique Martinet wrote:
> destroy code would incorrectly call close() if trans_mod exists after some
> hasty code cleanup: we need to make sure we only call close after create
> 
> Link: https://lkml.kernel.org/r/20220928214417.1749609-1-asmadeus@codewreck.org
> Link: https://lkml.kernel.org/r/00000000000015ac7905e97ebaed@google.com
> Reported-by: syzbot+67d13108d855f451cafc@syzkaller.appspotmail.com
> Reported-by: Leon Romanovsky <leon@kernel.org>
> Fixes: 3ff51294a055 ("9p: p9_client_create: use p9_client_destroy on failure")
> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
> ---
> v1->v2: also reset trans on create error
> v2->v3: fix silly compile errors
> 
> Sorry for the multiple mails, that's what I get for not even doing basic
> tests before talking...

Please always submit new patch versions as new one and don't reply-to.
It breaks flows of everyone who relies on proper email threading.

> 
>  net/9p/client.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/net/9p/client.c b/net/9p/client.c
> index bfa80f01992e..41e825a8da7c 100644
> --- a/net/9p/client.c
> +++ b/net/9p/client.c
> @@ -971,6 +971,7 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
>  	spin_lock_init(&clnt->lock);
>  	idr_init(&clnt->fids);
>  	idr_init(&clnt->reqs);
> +	clnt->trans = ERR_PTR(-EINVAL);
>  
>  	err = parse_opts(options, clnt);
>  	if (err < 0)
> @@ -990,8 +991,14 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
>  		 clnt, clnt->trans_mod, clnt->msize, clnt->proto_version);
>  
>  	err = clnt->trans_mod->create(clnt, dev_name, options);
> -	if (err)
> +	// ensure clnt->trans is initialized to call close() on destroy
> +	// if and only if create succeeded

Please use /* */ comment style.

> +	if (err < 0) {
> +		clnt->trans = ERR_PTR(err);
>  		goto out;
> +	}
> +	if (IS_ERR(clnt->trans))
> +		clnt->trans = NULL;
>  
>  	if (clnt->msize > clnt->trans_mod->maxsize) {
>  		clnt->msize = clnt->trans_mod->maxsize;
> @@ -1036,7 +1043,7 @@ void p9_client_destroy(struct p9_client *clnt)
>  
>  	p9_debug(P9_DEBUG_MUX, "clnt %p\n", clnt);
>  
> -	if (clnt->trans_mod)
> +	if (clnt->trans_mod && !IS_ERR(clnt->trans))

It is completely no-go to rely on internal value inside of structure after
failure in ->create() callback.

>  		clnt->trans_mod->close(clnt);
>  
>  	v9fs_put_trans(clnt->trans_mod);
> -- 
> 2.35.1
> 

  reply	other threads:[~2022-09-29  5:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-25 11:29 [syzbot] KASAN: use-after-free Read in rdma_close syzbot
2022-09-28 10:07 ` Leon Romanovsky
2022-09-28 10:43   ` asmadeus
2022-09-28 10:49     ` Leon Romanovsky
2022-09-28 11:23       ` asmadeus
2022-09-28 11:54         ` Leon Romanovsky
2022-09-28 12:57           ` Christian Schoenebeck
2022-09-28 21:52             ` asmadeus
2022-09-29  6:10               ` Leon Romanovsky
2022-09-28 21:44   ` [PATCH 1/2] 9p: client_create/destroy: only call trans_mod->close after create Dominique Martinet
2022-09-28 21:44     ` [PATCH 2/2] 9p: client_create: init fcall_cache earlier Dominique Martinet
2022-09-29  5:57       ` Leon Romanovsky
2022-09-29  7:03         ` Dominique Martinet
2022-09-28 21:58     ` [PATCH 1/2 v2] 9p: client_create/destroy: only call trans_mod->close after create Dominique Martinet
2022-09-28 22:19       ` [PATCH v3] " Dominique Martinet
2022-09-29  5:54         ` Leon Romanovsky [this message]
2022-09-29  7:24           ` Dominique Martinet
2022-12-30 10:34 ` [syzbot] KASAN: use-after-free Read in rdma_close syzbot
2023-01-13 10:35 ` syzbot
2023-01-27 10:36 ` syzbot
2023-02-10 10:36 ` syzbot
2023-02-24 10:37 ` syzbot
2023-03-10 10:38 ` syzbot
2023-03-24 10:38 ` syzbot
2023-04-07 10:38 ` syzbot
2023-04-21 10:39 ` syzbot
2023-05-05 10:40 ` syzbot
2023-05-19 10:40 ` syzbot
2023-06-02 10:42 ` syzbot
2023-06-02 10:57   ` Aleksandr Nogikh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YzUzAqsq803Z+rtr@unreal \
    --to=leon@kernel.org \
    --cc=asmadeus@codewreck.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux_oss@crudebyte.com \
    --cc=syzbot+67d13108d855f451cafc@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=v9fs-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).