All of lore.kernel.org
 help / color / mirror / Atom feed
* Suspicious kfree at the end of cm_write
@ 2021-04-23 14:37 Mark Langsdorf
  2021-04-23 15:09 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Langsdorf @ 2021-04-23 14:37 UTC (permalink / raw)
  To: linux-acpi

commit 03d1571d added an unconditional kfree() to the end of cm_write() 
in drivers/acpi/custom_method.c. I've been reviewing commits after the 
unm issue, and I think this code is wrong. If cm_write() is called with 
*ppos = 0 and count < table.length, the buf is kzalloc'd and immediately 
free'd. On subsequent calls to cm_write(), if cumulative count equals 
table.length, then the current contents of buf are passed to 
acpi_install_method. In the extremely unlikely case that buf has been 
reallocated and overwritten with a different but valid ACPI method, then 
some method other than the intended method could be installed. I'm not 
sure that this is a security issue but I don't think this code is correct.

It's a trivial patch to fix, but I'm not certain of my analysis. Could 
someone who is more familiar with cm_write review commit 03d1571d and 
tell me if I'm off base here?

--Mark Langsdorf


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Suspicious kfree at the end of cm_write
  2021-04-23 14:37 Suspicious kfree at the end of cm_write Mark Langsdorf
@ 2021-04-23 15:09 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-04-23 15:09 UTC (permalink / raw)
  To: Mark Langsdorf; +Cc: ACPI Devel Maling List

On Fri, Apr 23, 2021 at 4:38 PM Mark Langsdorf <mlangsdo@redhat.com> wrote:
>
> commit 03d1571d added an unconditional kfree() to the end of cm_write()
> in drivers/acpi/custom_method.c. I've been reviewing commits after the
> unm issue, and I think this code is wrong. If cm_write() is called with
> *ppos = 0 and count < table.length, the buf is kzalloc'd and immediately
> free'd. On subsequent calls to cm_write(), if cumulative count equals
> table.length, then the current contents of buf are passed to
> acpi_install_method. In the extremely unlikely case that buf has been
> reallocated and overwritten with a different but valid ACPI method, then
> some method other than the intended method could be installed. I'm not
> sure that this is a security issue but I don't think this code is correct.

The current code is not correct, so good catch!

If I'm not mistaken, it will lead to use-after-free on a subsequent
call to cm_write() it the current one does not write the entire
buffer.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-23 15:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 14:37 Suspicious kfree at the end of cm_write Mark Langsdorf
2021-04-23 15:09 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.