irqbalance/bugfix-set-hint-name-in-add_new_irq-to-avoid-segment.patch

82 lines
2.9 KiB
Diff

From 6f0ea91bfa9ee3016abf694e6fb9f46e7c847cc1 Mon Sep 17 00:00:00 2001
From: SuperSix173 <liuchao173@huawei.com>
Date: Mon, 1 Nov 2021 11:40:39 +0800
Subject: [PATCH] bugfix: set hint->name in add_new_irq to avoid segmentation
fault
hint->name is uninitialized in add_new_irq, so segmentation fault occurs
when calling strstr in get_usr_irq_policy
Signed-off-by: SuperSix173 <liuchao173@huawei.com>
---
classify.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/classify.c b/classify.c
index c5a2a35..560e932 100644
--- a/classify.c
+++ b/classify.c
@@ -607,6 +607,7 @@ static void add_new_irq(char *path, struct irq_info *hint, GList *proc_interrupt
struct irq_info *new;
struct user_irq_policy pol;
int irq = hint->irq;
+ GList *entry;
new = get_irq_info(irq);
if (new)
@@ -620,6 +621,11 @@ static void add_new_irq(char *path, struct irq_info *hint, GList *proc_interrupt
__add_banned_irq(irq, &banned_irqs);
new = get_irq_info(irq);
} else {
+ if (!hint->name) {
+ entry = g_list_find_custom(proc_interrupts, hint, compare_ints);
+ if (entry)
+ hint->name = ((struct irq_info *)entry->data)->name;
+ }
new = add_one_irq_to_db(path, hint, &pol);
if ((new != NULL) && (user_policy_list != NULL)) {
set_usr_irq_policy(hint->name, new);
@@ -660,6 +666,7 @@ static void build_one_dev_entry(const char *dirname, GList *tmp_irqs, int build_
if (irqnum && ((build_irq < 0) || (irqnum == build_irq))) {
hint.irq = irqnum;
hint.type = IRQ_TYPE_MSIX;
+ hint.name = NULL;
add_new_irq(devpath, &hint, tmp_irqs);
if (build_irq >= 0) {
log(TO_CONSOLE, LOG_INFO, "Hotplug dev irq: %d finished.\n", irqnum);
@@ -688,6 +695,7 @@ static void build_one_dev_entry(const char *dirname, GList *tmp_irqs, int build_
if ((build_irq < 0) || (irqnum == build_irq)) {
hint.irq = irqnum;
hint.type = IRQ_TYPE_LEGACY;
+ hint.name = NULL;
add_new_irq(devpath, &hint, tmp_irqs);
if (build_irq >= 0)
log(TO_CONSOLE, LOG_INFO, "Hotplug dev irq: %d finished.\n", irqnum);
@@ -764,11 +772,13 @@ static struct irq_info * build_dev_irqs(GList *tmp_irqs, int build_irq)
int proc_irq_hotplug(char *savedline, int irq, struct irq_info **pinfo)
{
struct irq_info tmp_info = {0};
+ GList *tmp_list = NULL;
/* firstly, init irq info by parse savedline */
init_irq_class_and_type(savedline, &tmp_info, irq);
+ tmp_list = g_list_append(tmp_list, &tmp_info);
/* secondly, init irq info by read device info */
- *pinfo = build_dev_irqs(interrupts_db, irq);
+ *pinfo = build_dev_irqs(tmp_list, irq);
if (*pinfo == NULL) {
add_new_irq(NULL, &tmp_info, interrupts_db);
*pinfo = get_irq_info(irq);
@@ -779,6 +789,8 @@ int proc_irq_hotplug(char *savedline, int irq, struct irq_info **pinfo)
}
force_rebalance_irq(*pinfo, NULL);
+ free(tmp_info.name);
+ g_list_free(tmp_list);
return 0;
}
--
1.8.3.1