public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandra Winter <wintera@linux.ibm.com>
To: yskelg@gmail.com, Thorsten Winkler <twinkler@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Markus Elfring <Markus.Elfring@web.de>
Cc: MichelleJin <shjy180909@gmail.com>,
	linux-s390@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] s390/netiucv: handle memory allocation failure in conn_action_start()
Date: Tue, 25 Jun 2024 11:09:20 +0200	[thread overview]
Message-ID: <beac131a-6c8c-4ed7-8714-416c57ea0fbb@linux.ibm.com> (raw)
In-Reply-To: <20240625024819.26299-2-yskelg@gmail.com>



On 25.06.24 04:48, yskelg@gmail.com wrote:
> From: Yunseong Kim <yskelg@gmail.com>

Thank you very much Yunseong, for finding and reporting this potential 
null-pointer dereference.
And thank you Markus Elfring for your valuable comments.

> 
> A null pointer is stored in the data structure member "path" after a call
> of the function "iucv_path_alloc" failed. This pointer was passed to
> a subsequent call of the function "iucv_path_connect" where an undesirable
> dereference will be performed then. Thus add a corresponding return value
> check. This prevent null pointer dereferenced kernel panic when memory
> exhausted situation with the netiucv driver operating as an FSM state
> in "conn_action_start".

I would prefer an even shorter commit message. Allocating memory
without checking for failure is a common error pattern, I think.

> 
> Fixes: eebce3856737 ("[S390]: Adapt netiucv driver to new IUCV API")
> Cc: linux-s390@vger.kernel.org
> Signed-off-by: Yunseong Kim <yskelg@gmail.com>
> ---
>  drivers/s390/net/netiucv.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
> index 039e18d46f76..d3ae78c0240f 100644
> --- a/drivers/s390/net/netiucv.c
> +++ b/drivers/s390/net/netiucv.c
> @@ -855,6 +855,9 @@ static void conn_action_start(fsm_instance *fi, int event, void *arg)
>  
>  	fsm_newstate(fi, CONN_STATE_SETUPWAIT);
>  	conn->path = iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT, 0, GFP_KERNEL);
> +	if (!conn->path)
> +		return;
> +


On 25.06.24 09:24, Markus Elfring wrote:
> 
> Would the following statement variant become more appropriate here?
> 
> +		return -ENOMEM;

conn_action_start(), like the other fsm functions, does not have a return value.
But simply returning will not prevent the next fsm function from trying to use
conn->path.

So I think you need to do
fsm_newstate(fi, CONN_STATE_CONNERR);
before you return.

You could use rc = -ENOMEM and a goto to the IUCV_DBF_TEXT_ debug message,
if you want to. But I am not too concerned about the details of error handling:
If your memory is so scarce that you cannot even allocate a handful of bytes,
then you should be seeing warnings all over the place.















      parent reply	other threads:[~2024-06-25  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25  2:48 [PATCH v2] s390/netiucv: handle memory allocation failure in conn_action_start() yskelg
2024-06-25  7:24 ` Markus Elfring
2024-06-25  9:09 ` Alexandra Winter [this message]

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=beac131a-6c8c-4ed7-8714-416c57ea0fbb@linux.ibm.com \
    --to=wintera@linux.ibm.com \
    --cc=Markus.Elfring@web.de \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=shjy180909@gmail.com \
    --cc=svens@linux.ibm.com \
    --cc=twinkler@linux.ibm.com \
    --cc=yskelg@gmail.com \
    /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