Skip to contentSkip to conversation

tracing: Add NULL checks for buffer in ring_buffer_free_read_page()

PATCH In review Sasha Levin 2 participants 4 messages Mar 1, 2023

Subsystems (3)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/3 tracing: Add NULL checks for buffer in ring_buffer_free_read_page()

From: Jia-Ju Bai <[email protected]>

[ Upstream commit 3e4272b9954094907f16861199728f14002fcaf6 ]

In a previous commit 7433632c9ff6, buffer, buffer->buffers and buffer->buffers[cpu] in ring_buffer_wake_waiters() can be NULL, and thus the related checks are added.

However, in the same call stack, these variables are also used in ring_buffer_free_read_page():

tracing_buffers_release()
ring_buffer_wake_waiters(iter->array_buffer->buffer)

    cpu_buffer = buffer->buffers[cpu] -> Add checks by previous commit
  ring_buffer_free_read_page(iter->array_buffer->buffer)
    cpu_buffer = buffer->buffers[cpu] -> No check

Thus, to avod possible null-pointer derefernces, the related checks should be added.

These results are reported by a static tool designed by myself.

---
 kernel/trace/ring_buffer.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/trace/ring_buffer.c +6 -1
index 5e5b0c067f611..bef3d01b8ff61 100644
@@ -4685,11 +4685,16 @@ EXPORT_SYMBOL_GPL(ring_buffer_alloc_read_page);
  */
 void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data)
 {
-	struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
+	struct ring_buffer_per_cpu *cpu_buffer;
 	struct buffer_data_page *bpage = data;
 	struct page *page = virt_to_page(bpage);
 	unsigned long flags;
 
+	if (!buffer || !buffer->buffers || !buffer->buffers[cpu])
+		return;
+
+	cpu_buffer = buffer->buffers[cpu];
+
 	/* If the page is still in use someplace else, we can't reuse it */
 	if (page_ref_count(page) > 1)
 		goto out;
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH 2/3 efi: efivars: prevent double registration

From: Johan Hovold <[email protected]>

[ Upstream commit 0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7 ]

Add the missing sanity check to efivars_register() so that it is no longer possible to override an already registered set of efivar ops (without first deregistering them).

This can help debug initialisation ordering issues where drivers have so far unknowingly been relying on overriding the generic ops.

---
 drivers/firmware/efi/vars.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/firmware/efi/vars.c +11 -2
index e619ced030d52..462e88b9d2ba4 100644
@@ -1195,19 +1195,28 @@ int efivars_register(struct efivars *efivars,
 		     const struct efivar_operations *ops,
 		     struct kobject *kobject)
 {
+	int rv;
+
 	if (down_interruptible(&efivars_lock))
 		return -EINTR;
 
+	if (__efivars) {
+		pr_warn("efivars already registered\n");
+		rv = -EBUSY;
+		goto out;
+	}
+
 	efivars->ops = ops;
 	efivars->kobject = kobject;
 
 	__efivars = efivars;
 
 	pr_info("Registered efivars operations\n");
-
+	rv = 0;
+out:
 	up(&efivars_lock);
 
-	return 0;
+	return rv;
 }
 EXPORT_SYMBOL_GPL(efivars_register);
 
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH AUTOSEL 4.19 2/3] efi: efivars: prevent double registration

Quoted 9 lines · Sasha Levin

From: Johan Hovold <[email protected]>

[ Upstream commit 0217a40d7ba6e71d7f3422fbe89b436e8ee7ece7 ]

Add the missing sanity check to efivars_register() so that it is no longer possible to override an already registered set of efivar ops (without first deregistering them).

Quoted 6 lines

This can help debug initialisation ordering issues where drivers have so far unknowingly been relying on overriding the generic ops.

NAK this is not a bugfix.

Quoted 42 lines
---
 drivers/firmware/efi/vars.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/firmware/efi/vars.c +11 -3
index e619ced030d52..462e88b9d2ba4 100644
@@ -1195,19 +1195,28 @@ int efivars_register(struct efivars *efivars,
                     const struct efivar_operations *ops,
                     struct kobject *kobject)
 {
+       int rv;
+
        if (down_interruptible(&efivars_lock))
                return -EINTR;
 
+       if (__efivars) {
+               pr_warn("efivars already registered\n");
+               rv = -EBUSY;
+               goto out;
+       }
+
        efivars->ops = ops;
        efivars->kobject = kobject;
 
        __efivars = efivars;
 
        pr_info("Registered efivars operations\n");
-
+       rv = 0;
+out:
        up(&efivars_lock);
 
-       return 0;
+       return rv;
 }
 EXPORT_SYMBOL_GPL(efivars_register);
 
--

2.39.2

author maintainer
#3 lore raw

PATCH 3/3 firmware/efi sysfb_efi: Add quirk for Lenovo IdeaPad Duet 3

In reply to Sasha Levin

From: Darrell Kavanagh <[email protected]>

[ Upstream commit e1d447157f232c650e6f32c9fb89ff3d0207c69a ]

Another Lenovo convertable which reports a landscape resolution of 1920x1200 with a pitch of (1920 * 4) bytes, while the actual framebuffer has a resolution of 1200x1920 with a pitch of (1200 * 4) bytes.

---
 arch/x86/kernel/sysfb_efi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/x86/kernel/sysfb_efi.c +8 -0
index 897da526e40e6..dd8d7636c5420 100644
@@ -265,6 +265,14 @@ static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = {
 					"Lenovo ideapad D330-10IGM"),
 		},
 	},
+	{
+		/* Lenovo IdeaPad Duet 3 10IGL5 with 1200x1920 portrait screen */
+		.matches = {
+			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_VERSION,
+					"IdeaPad Duet 3 10IGL5"),
+		},
+	},
 	{},
 };
 
Signature · 1 line
2.39.2