[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210324184257.GV3014244@iweiny-DESK2.sc.intel.com>
Date: Wed, 24 Mar 2021 11:42:57 -0700
From: Ira Weiny <ira.weiny@...el.com>
To: Robert Richter <rrichter@....com>
Cc: Alison Schofield <alison.schofield@...el.com>,
Vishal Verma <vishal.l.verma@...el.com>,
Ben Widawsky <ben.widawsky@...el.com>,
Dan Williams <dan.j.williams@...el.com>,
linux-cxl@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] cxl/mem: Force array size of mem_commands[] to
CXL_MEM_COMMAND_ID_MAX
On Wed, Mar 24, 2021 at 03:16:35PM +0100, Robert Richter wrote:
> Typically the mem_commands[] array is in sync with 'enum { CXL_CMDS }'.
> Current code works well.
>
> However, the array size of mem_commands[] may not strictly be the same
> as CXL_MEM_COMMAND_ID_MAX. E.g. if a new CXL_CMD() is added that is
> guarded by #ifdefs, the array could be shorter. This could lead then
> further to an out-of-bounds array access in cxl_validate_cmd_from_user().
>
> Fix this by forcing the array size to CXL_MEM_COMMAND_ID_MAX. This
> also adds range checks for array items in mem_commands[] at compile
> time.
Can't we use ARRAY_SIZE?
Ira
>
> Signed-off-by: Robert Richter <rrichter@....com>
> ---
> drivers/cxl/mem.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
> index 244cb7d89678..ecfc9ccdba8d 100644
> --- a/drivers/cxl/mem.c
> +++ b/drivers/cxl/mem.c
> @@ -169,7 +169,7 @@ struct cxl_mem_command {
> * table will be validated against the user's input. For example, if size_in is
> * 0, and the user passed in 1, it is an error.
> */
> -static struct cxl_mem_command mem_commands[] = {
> +static struct cxl_mem_command mem_commands[CXL_MEM_COMMAND_ID_MAX] = {
> CXL_CMD(IDENTIFY, 0, 0x43, CXL_CMD_FLAG_FORCE_ENABLE),
> #ifdef CONFIG_CXL_MEM_RAW_COMMANDS
> CXL_CMD(RAW, ~0, ~0, 0),
> --
> 2.29.2
>
Powered by blists - more mailing lists