cxl/mem: Fixes to IOCTL interface
Subsystems (2)
PATCH 1/1 cxl/mem: Fixes to IOCTL interface
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed. As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
This bug was introduced in v5 of the patch and did not exist in prior revisions.
While here, adjust the variable 'j' found in patch review by Konrad.
--- drivers/cxl/mem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/cxl/mem.c +6 -4
@@ -514,8 +514,10 @@ static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm,if (cmd->info.size_in) { mbox_cmd.payload_in =vmemdup_user (u64_to_user_ptr (in_payload), cmd->info.size_in); -if (IS_ERR (mbox_cmd.payload_in)) +if (IS_ERR (mbox_cmd.payload_in)) { +kvfree (mbox_cmd.payload_out);return PTR_ERR (mbox_cmd.payload_in); + } } rc =cxl_mem_mbox_get (cxlm);
@@ -696,7 +698,7 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,struct device *dev = &cxlmd->dev;struct cxl_mem_command *cmd;u32 n_commands; -int j =0 ; +int cmds =0 ;dev_dbg (dev,"Query IOCTL\n" );
@@ -714,10 +716,10 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,cxl_for_each_cmd (cmd) {const struct cxl_command_info *info = &cmd->info; -if (copy_to_user (&q->commands[j++], info,sizeof (*info))) +if (copy_to_user (&q->commands[cmds++], info,sizeof (*info)))return -EFAULT ; -if (j == n_commands) +if (cmds == n_commands)break ; }
Signature · 4 lines
2.30.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Quoted 11 lines · Ben Widawsky
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed. As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
This bug was introduced in v5 of the patch and did not exist in prior revisions.
Thanks for the quick turnaround, but I think that speed introduced some issues...
Quoted 1 line
While here, adjust the variable 'j' found in patch review by Konrad.
Please split this pure cleanup to its own patch. The subject says "Fixes", but it's only the one fix.
Quoted 3 lines
Cc Al Viro <[email protected]>Reported-by Konrad Rzeszutek Wilk <[email protected]>
Since the commit is upstream add a "Fixes" line:
Quoted 3 lines
Signed-off-by Ben Widawsky <[email protected]>Reviewed-by Dan Williams <[email protected]> (v2)Reviewed-by Jonathan Cameron <[email protected]>
Jonathan and I didn't pre-review this.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Quoted 13 lines · Dan Williams
Quoted 11 lines · Ben Widawsky
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed. As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
This bug was introduced in v5 of the patch and did not exist in prior revisions.
Quoted 8 lines
Thanks for the quick turnaround, but I think that speed introduced some issues...
Quoted 1 line
While here, adjust the variable 'j' found in patch review by Konrad.
Please split this pure cleanup to its own patch. The subject says "Fixes", but it's only the one fix.
This was intentional. I pinged you internally to just drop it if you don't like to combine these kind of things. It didn't feel worthwhile to introduce a new patch to change the 'j'. I agree with Konrad that 'j' is not the best variable name to use. Konrad, maybe you'd like to send a fixup for that one?
I will drop this hunk.
Quoted 6 lines
Quoted 3 lines
Cc Al Viro <[email protected]>Reported-by Konrad Rzeszutek Wilk <[email protected]>Since the commit is upstream add a "Fixes" line:
Quoted 7 lines
Fixes 583fa5e71cae ('cxl/mem: Add basic IOCTL interface")Quoted 3 lines
Signed-off-by Ben Widawsky <[email protected]>Reviewed-by Dan Williams <[email protected]> (v2)Reviewed-by Jonathan Cameron <[email protected]>Jonathan and I didn't pre-review this.
My bad on this. It was a mistake that I pulled the info from the original patch I was fixing.
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Quoted 18 lines · Ben Widawsky
Quoted 16 lines · Dan Williams
Quoted 11 lines · Ben Widawsky
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed. As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
This bug was introduced in v5 of the patch and did not exist in prior revisions.
Thanks for the quick turnaround, but I think that speed introduced some issues...
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
While here, adjust the variable 'j' found in patch review by Konrad.
Please split this pure cleanup to its own patch. The subject says "Fixes", but it's only the one fix.
This was intentional. I pinged you internally to just drop it if you don't like to combine these kind of things.
Apologies, I've been offline this weekend and missed that. I will point out though that in general I will not change patch contents on the way upstream. The adjusted patch must appear on the mailing list. The new korg support for attaching attestation to patches requires they all be on the list, so even small adjustments need new postings.
Quoted 2 lines
It didn't feel worthwhile to introduce a new
patch to change the 'j'.
Janitorial patches happen all the time, so I think it's ok.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
..little snip..
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
While here, adjust the variable 'j' found in patch review by Konrad.
Please split this pure cleanup to its own patch. The subject says "Fixes", but it's only the one fix.
This was intentional. I pinged you internally to just drop it if you don't like to combine these kind of things. It didn't feel worthwhile to introduce a new patch to change the 'j'. I agree with Konrad that 'j' is not the best variable name to use. Konrad, maybe you'd like to send a fixup for that one?
Sure, but let do that _after_ Dan does his git-pull so that the scripts/get_maintainers.pl will nicely pull the right emails :-)
Quoted 2 lines
I will drop this hunk.
+1
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH v2 1/1 cxl/mem: Fix potential memory leak
In reply to Ben WidawskyWhen submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed too.
As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
--- drivers/cxl/mem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/mem.c +3 -1
@@ -514,8 +514,10 @@ static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm,if (cmd->info.size_in) { mbox_cmd.payload_in =vmemdup_user (u64_to_user_ptr (in_payload), cmd->info.size_in); -if (IS_ERR (mbox_cmd.payload_in)) +if (IS_ERR (mbox_cmd.payload_in)) { +kvfree (mbox_cmd.payload_out);return PTR_ERR (mbox_cmd.payload_in); + } } rc =cxl_mem_mbox_get (cxlm);
Signature · 4 lines
2.30.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [PATCH v2] cxl/mem: Fix potential memory leak
Quoted 11 lines · On Sat, 20 Feb 2021 19:58:46 -0800 Ben Widawsky <[email protected]> wrote:
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed too.
As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
Fixes 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")Reported-by Konrad Rzeszutek Wilk <[email protected]>Signed-off-by Ben Widawsky <[email protected]>
I'd probably have used a goto and label but I guess this works fine a well. FWIW on such a small patch.
Quoted 10 lines
--- drivers/cxl/mem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/mem.c +0
-0@@ -514,8 +514,10 @@ static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm,if (cmd->info.size_in) {
drivers/cxl/mem.c static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm, · line 523
Quoted 10 lines
drivers/cxl/mem.c +3
-1mbox_cmd.payload_in =vmemdup_user (u64_to_user_ptr (in_payload), cmd->info.size_in); -if (IS_ERR (mbox_cmd.payload_in)) +if (IS_ERR (mbox_cmd.payload_in)) { +kvfree (mbox_cmd.payload_out);return PTR_ERR (mbox_cmd.payload_in); + } } rc =cxl_mem_mbox_get (cxlm);
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [PATCH v2] cxl/mem: Fix potential memory leak
In reply to Ben WidawskyQuoted 10 lines · Ben Widawsky
When submitting a command for userspace, input and output payload bounce buffers are allocated. For a given command, both input and output buffers may exist and so when allocation of the input buffer fails, the output buffer must be freed too.
As far as I can tell, userspace can't easily exploit the leak to OOM a machine unless the machine was already near OOM state.
Fixes 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")Reported-by Konrad Rzeszutek Wilk <[email protected]>
And lets add the other R-tag:
Thank you for quick turn-around!
Quoted 24 lines
Signed-off-by Ben Widawsky <[email protected]>--- drivers/cxl/mem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/mem.c +3
-1@@ -514,8 +514,10 @@ static int handle_mailbox_cmd_from_user(struct cxl_mem *cxlm,if (cmd->info.size_in) { mbox_cmd.payload_in =vmemdup_user (u64_to_user_ptr (in_payload), cmd->info.size_in); -if (IS_ERR (mbox_cmd.payload_in)) +if (IS_ERR (mbox_cmd.payload_in)) { +kvfree (mbox_cmd.payload_out);return PTR_ERR (mbox_cmd.payload_in); + } } rc =cxl_mem_mbox_get (cxlm);Signature · 1 line
2.30.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]