public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Corey Minyard <corey@minyard.net>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Corey Minyard <cminyard@mvista.com>,
	openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] ipmi:msghandler: Fix potential memory corruption in ipmi_create_user()
Date: Mon, 5 May 2025 11:09:07 -0500	[thread overview]
Message-ID: <aBjioyOkty40OVd5@mail.minyard.net> (raw)
In-Reply-To: <aBjMZ8RYrOt6NOgi@stanley.mountain>

On Mon, May 05, 2025 at 05:34:15PM +0300, Dan Carpenter wrote:
> The "intf" list iterator is an invalid pointer if the correct
> "intf->intf_num" is not found.  Calling atomic_dec(&intf->nr_users) on
> and invalid pointer will lead to memory corruption.
> 
> We don't really need to call atomic_dec() if we haven't called
> atomic_add_return() so update the if (intf->in_shutdown) path as well.

Thanks, this is in my tree now.

-corey

> 
> Fixes: 8e76741c3d8b ("ipmi: Add a limit on the number of users that may use IPMI")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/char/ipmi/ipmi_msghandler.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 8b2c3fca9c4c..064944ae9fdc 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -1240,12 +1240,12 @@ int ipmi_create_user(unsigned int          if_num,
>  	}
>  	/* Not found, return an error */
>  	rv = -EINVAL;
> -	goto out_kfree;
> +	goto out_unlock;
>  
>   found:
>  	if (intf->in_shutdown) {
>  		rv = -ENODEV;
> -		goto out_kfree;
> +		goto out_unlock;
>  	}
>  
>  	if (atomic_add_return(1, &intf->nr_users) > max_users) {
> @@ -1293,6 +1293,7 @@ int ipmi_create_user(unsigned int          if_num,
>  	} else {
>  		*user = new_user;
>  	}
> +out_unlock:
>  	mutex_unlock(&ipmi_interfaces_mutex);
>  	return rv;
>  }
> -- 
> 2.47.2
> 

      reply	other threads:[~2025-05-05 16:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 14:34 [PATCH] ipmi:msghandler: Fix potential memory corruption in ipmi_create_user() Dan Carpenter
2025-05-05 16:09 ` Corey Minyard [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=aBjioyOkty40OVd5@mail.minyard.net \
    --to=corey@minyard.net \
    --cc=cminyard@mvista.com \
    --cc=dan.carpenter@linaro.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openipmi-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