public inbox for linux-cxl@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: jonathan.cameron@huawei.com, alison.schofield@intel.com,
	vishal.l.verma@intel.com, ira.weiny@intel.com,
	dan.j.williams@intel.com, linux-cxl@vger.kernel.org
Subject: Re: [PATCH 2/2] cxl/mbox: return appropriate error in cxl_payload_from_user_allowed()
Date: Mon, 23 Feb 2026 15:40:59 -0700	[thread overview]
Message-ID: <d1852c63-16b9-41a8-a9da-a3e240fd5532@intel.com> (raw)
In-Reply-To: <20260220001618.963490-3-dave@stgolabs.net>



On 2/19/26 5:16 PM, Davidlohr Bueso wrote:
> Make cxl_payload_from_user_allowed() return int such that the it can
> distinguish between different errors. The payload size failure is not
> well represented by EBUSY (exclusive access by the kernel).
> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Since this isn't a fix, I'm going to wait and apply it to cxl/next later after the fix goes in 7.0-rc2. Please remind me if I forget.

> ---
>  drivers/cxl/core/mbox.c | 32 +++++++++++++++++++-------------
>  1 file changed, 19 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
> index e7a6452bf544..164da335fa33 100644
> --- a/drivers/cxl/core/mbox.c
> +++ b/drivers/cxl/core/mbox.c
> @@ -314,8 +314,9 @@ static bool cxl_mem_raw_command_allowed(u16 opcode)
>   * @in_size: Size of @payload_in in bytes.
>   *
>   * Return:
> - *  * true	- payload_in passes check for @opcode.
> - *  * false	- payload_in contains invalid or unsupported values.
> + *  * %0	- payload_in passes check for @opcode.
> + *  * %-EINVAL	- payload_in is too small for the opcode.
> + *  * %-EBUSY	- payload_in contains unsupported values.
>   *
>   * The driver may inspect payload contents before sending a mailbox
>   * command from user space to the device. The intent is to reject
> @@ -326,40 +327,44 @@ static bool cxl_mem_raw_command_allowed(u16 opcode)
>   *
>   * The specific checks are determined by the opcode.
>   */
> -static bool cxl_payload_from_user_allowed(u16 opcode, void *payload_in,
> -					  size_t in_size)
> +static int cxl_payload_from_user_allowed(u16 opcode, void *payload_in,
> +					 size_t in_size)
>  {
>  	switch (opcode) {
>  	case CXL_MBOX_OP_SET_PARTITION_INFO: {
>  		struct cxl_mbox_set_partition_info *pi = payload_in;
>  
>  		if (in_size < sizeof(*pi))
> -			return false;
> +			return -EINVAL;
>  		if (pi->flags & CXL_SET_PARTITION_IMMEDIATE_FLAG)
> -			return false;
> +			return -EBUSY;
>  		break;
>  	}
>  	case CXL_MBOX_OP_CLEAR_LOG: {
>  		const uuid_t *uuid = (uuid_t *)payload_in;
>  
>  		if (in_size < sizeof(uuid_t))
> -			return false;
> +			return -EINVAL;
>  		/*
> -		 * Restrict the ‘Clear log’ action to only apply to
> +		 * Restrict the 'Clear log' action to only apply to
>  		 * Vendor debug logs.
>  		 */
> -		return uuid_equal(uuid, &DEFINE_CXL_VENDOR_DEBUG_UUID);
> +		if (!uuid_equal(uuid, &DEFINE_CXL_VENDOR_DEBUG_UUID))
> +			return -EBUSY;
> +		break;
>  	}
>  	default:
>  		break;
>  	}
> -	return true;
> +	return 0;
>  }
>  
>  static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox_cmd,
>  			     struct cxl_mailbox *cxl_mbox, u16 opcode,
>  			     size_t in_size, size_t out_size, u64 in_payload)
>  {
> +	int rc;
> +
>  	*mbox_cmd = (struct cxl_mbox_cmd) {
>  		.opcode = opcode,
>  		.size_in = in_size,
> @@ -371,12 +376,13 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox_cmd,
>  		if (IS_ERR(mbox_cmd->payload_in))
>  			return PTR_ERR(mbox_cmd->payload_in);
>  
> -		if (!cxl_payload_from_user_allowed(opcode, mbox_cmd->payload_in,
> -						  in_size)) {
> +		rc = cxl_payload_from_user_allowed(opcode, mbox_cmd->payload_in,
> +						   in_size);
> +		if (rc) {
>  			dev_dbg(cxl_mbox->host, "%s: input payload not allowed\n",
>  				cxl_mem_opcode_to_name(opcode));
>  			kvfree(mbox_cmd->payload_in);
> -			return -EBUSY;
> +			return rc;
>  		}
>  	}
>  


  parent reply	other threads:[~2026-02-23 22:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20  0:16 [PATCH 0/2] cxl/mbox: fix undersized payload handling in cxl_payload_from_user_allowed() Davidlohr Bueso
2026-02-20  0:16 ` [PATCH 1/2] cxl/mbox: validate payload size before accessing contents " Davidlohr Bueso
2026-02-23 19:23   ` Alison Schofield
2026-02-23 22:39   ` Dave Jiang
2026-02-20  0:16 ` [PATCH 2/2] cxl/mbox: return appropriate error " Davidlohr Bueso
2026-02-20 22:14   ` Alison Schofield
2026-02-21 18:55     ` Davidlohr Bueso
2026-02-23 19:27   ` Alison Schofield
2026-02-23 22:40   ` Dave Jiang [this message]
2026-02-27 13:38   ` Jonathan Cameron
2026-02-20 17:23 ` [PATCH 0/2] cxl/mbox: fix undersized payload handling " Dave Jiang

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=d1852c63-16b9-41a8-a9da-a3e240fd5532@intel.com \
    --to=dave.jiang@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=vishal.l.verma@intel.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