Bug 1366512 - lparstat segfault if 'SPU' line in /proc/interrupts is too long
Summary: lparstat segfault if 'SPU' line in /proc/interrupts is too long
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: powerpc-utils   
(Show other bugs)
Version: 7.2
Hardware: ppc64
OS: Linux
unspecified
high
Target Milestone: rc
: 7.3
Assignee: Rafael Fonseca
QA Contact: Frantisek Sumsal
Jiri Herrmann
URL:
Whiteboard:
Keywords: OtherQA, Patch
: 1367695 (view as bug list)
Depends On:
Blocks: 1230910 1274397 1364088
TreeView+ depends on / blocked
 
Reported: 2016-08-12 07:44 UTC by Qi Guo [Flos]
Modified: 2016-11-04 05:13 UTC (History)
16 users (show)

Fixed In Version: powerpc-utils-1.3.2-2
Doc Type: Release Note
Doc Text:
"lparstat" no longer fails due to long lines in `/proc/interrupts` Prior to this update, if the SPU line in the `/proc/interrupts` file was longer than 512 characters, using the "lparstat" command failed. With this update, "lparstat" properly parses interrupt lines, and thus returns correct results in the described circumstances.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-04 05:13:06 UTC
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2016:2389 normal SHIPPED_LIVE powerpc-utils bug fix and enhancement update 2016-11-03 13:53:57 UTC
IBM Linux Technology Center 144850 None None None 2016-08-12 13:21 UTC
Red Hat Knowledge Base (Solution) 2524191 None None None 2016-08-12 14:48 UTC

Description Qi Guo [Flos] 2016-08-12 07:44:42 UTC
Description of problem:
> lparstat segfault if 'SPU' line in /proc/interrupts is too long

Version-Release number of selected component (if applicable):
> powerpc-utils-1.2.26-2.el7

How reproducible:
> Randomly

Steps to Reproduce:

1. Find a powerpc system and check the SPU line of /proc/interrupts is more than 512 characters:

$ cat proc/interrupts | grep SPU | wc -c
907

2. Execute the command:

# /usr/sbin/lparstat -i

Actual results:
>  Segmentation fault can occur

Expected results:
> lparstat should return correct result without segfault

Additional info:
> upstream bug:
  https://github.com/nfont/powerpc-utils/issues/8

Comment 2 IBM Bug Proxy 2016-08-12 13:30:51 UTC
------- Comment From fnovak@us.ibm.com 2016-08-12 09:20 EDT-------
reverse RH1366512 - lparstat segfault if 'SPU' line in /proc/interrupts is too long

Comment 3 IBM Bug Proxy 2016-08-16 14:40:50 UTC
------- Comment From allenjoh@us.ibm.com 2016-08-16 10:33 EDT-------
*** This bug has been marked as a duplicate of bug 144709 ***

Comment 4 Qi Guo [Flos] 2016-08-16 15:20:10 UTC
Hello,

I don't think this bug is a duplicate of bug 144709 which is opened for the evolution-2.0.2-3. Could you please double check it?

Thanks.

Comment 5 IBM Bug Proxy 2016-08-16 15:40:29 UTC
------- Comment From allenjoh@us.ibm.com 2016-08-16 11:34 EDT-------
(In reply to comment #7)
> Hello,
>
> I don't think this bug is a duplicate of bug 144709 which is opened for the
> evolution-2.0.2-3. Could you please double check it?
>
> Thanks.

That's IBM bugzilla 144709. Didn't mean to mark the mirrored RH bug a a duplicate, sorry about that.

------- Comment From allenjoh@us.ibm.com 2016-08-16 11:36 EDT-------
*** This bug has been marked as a duplicate of bug 144709 ***

Comment 6 Hanns-Joachim Uhl 2016-08-16 18:16:19 UTC
Hello Red Hat / Qi Guo,
... the patch currently being posted for this bugzilla is
https://groups.google.com/forum/#!topic/powerpc-utils-devel/mmqVVIzZ5Y4
("[PATCH] lparstat: Fix segfault when parsing /proc/interrupts")
... would it be possible that you give this patch a try
whether it will resolve this bugzilla ..?
Please advise ...
Thanks for your support.

Comment 7 Qi Guo [Flos] 2016-08-17 14:32:47 UTC
Hello Hanns,

Thanks for bringing up the information. I copy the posted patch here from the google groups for discussion:

#####################
Signed-off-by: John Allen <jal...@linux.vnet.ibm.com>
---
diff --git a/src/lparstat.c b/src/lparstat.c
index ebe0d13..81ceb93 100644
--- a/src/lparstat.c
+++ b/src/lparstat.c
@@ -203,7 +203,8 @@ int parse_lparcfg()
 int parse_proc_ints()
 {
         FILE *f;
-        char line[512];
+        char *line = NULL;
+        size_t n = 0;
         char *value;
         struct sysentry *se;
         long long int phint = 0;
@@ -214,7 +215,7 @@ int parse_proc_ints()
                 return -1;
         }

-        while (fgets(line, 512, f) != NULL) {
+        while (getline(&line, &n, f) != -1) {
                 /* we just need the SPU line */
                 if (line[0] != 'S' || line[1] != 'P' || line[2] != 'U') <<<---- HERE
                         continue;
@@ -224,8 +225,11 @@ int parse_proc_ints()
                         v = atoi(value);
                         phint += v;
                 }
+
+                break;
         }

+        free(line);
         fclose(f);

         se = get_sysentry("phint"); 

#####################

Is it possible that the first character of 'SPU:' line is not 'S'? Given the code in the kernel, the 'prec' can be greater than 3:

int arch_show_interrupts(struct seq_file *p, int prec)
{
...
        seq_printf(p, "%*s: ", prec, "SPU");
        for_each_online_cpu(j)
                seq_printf(p, "%10u ", per_cpu(irq_stat, j).spurious_irqs);
        seq_printf(p, "  Spurious interrupts\n");
...
}

int show_interrupts(struct seq_file *p, void *v)
{
        static int prec;

        unsigned long flags, any_count = 0;
        int i = *(loff_t *) v, j;
        struct irqaction *action;
        struct irq_desc *desc;

        if (i > ACTUAL_NR_IRQS)
                return 0;

        if (i == ACTUAL_NR_IRQS)
                return arch_show_interrupts(p, prec);

        /* print header and calculate the width of the first column */
        if (i == 0) {
                for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
                        j *= 10;

                seq_printf(p, "%*s", prec + 8, "");
                for_each_online_cpu(j)
                        seq_printf(p, "CPU%-8d", j);
                seq_putc(p, '\n');
        }
...
}

Please kindly share your thoughts. Thanks.

Regards,
Flos

Comment 8 IBM Bug Proxy 2016-08-17 18:01:08 UTC
------- Comment From hannsj_uhl@de.ibm.com 2016-08-17 13:59 EDT-------
Comment from  John Allen 2016-08-17 13:18:51 EDT

(In reply to comment #11)
> Is it possible that the first character of 'SPU:' line is not 'S'? Given the
> code in the kernel, the 'prec' can be greater than 3:

Ah yes, good catch. If any interrupt numbers exceed 3 characters, whitespace will be added to the beginning of the line to keep the columns aligned. I will submit a follow up patch that ignores any whitespace at the beginning of the line.

Comment 9 Rafael Fonseca 2016-08-22 11:44:01 UTC
*** Bug 1367695 has been marked as a duplicate of this bug. ***

Comment 10 IBM Bug Proxy 2016-08-24 09:10:38 UTC
------- Comment From hannsj_uhl@de.ibm.com 2016-08-24 05:04 EDT-------
fyi ... an updated patch is now upstream posted at
and upstream accepted as git commit
https://github.com/nfont/powerpc-utils/commit/3c3a53825248e1ef52ee203c968f643c26820cc5
("lparstat: Fix segfault when parsing /proc/interrupts")
.
... please give it a try as soon as possibe whether it will fix this bugzilla ...
... thanks in advance ...

Comment 11 Qi Guo [Flos] 2016-08-24 09:29:31 UTC
Hi Hanns,

Seems the possible leading white space issue is not fixed in this patch. Any other bug is created for it? Thanks.

Regards,
Flos

Comment 12 IBM Bug Proxy 2016-08-24 14:20:52 UTC
------- Comment From allenjoh@us.ibm.com 2016-08-24 10:15 EDT-------
Patch for the whitespace issue will be submitted soon--planning on submitting that this afternoon. There currently isn't another bug open to track that issue. I was planning on tracking that fix in this bug, but if it would be preferred, another bug can be opened to track the whitespace issue.

Comment 13 IBM Bug Proxy 2016-08-27 16:11:46 UTC
------- Comment From hannsj_uhl@de.ibm.com 2016-08-27 12:09 EDT-------
(In reply to comment #19)
> Patch for the whitespace issue will be submitted soon--planning on
> submitting that this afternoon. ...
... which is now accepted upstream as git commit
https://github.com/nfont/powerpc-utils/commit/b071e81d8cd71af496d5c5b36371c30449051def
("lparstat: Ignore whitespace at beginning of /proc/interrupts SPU line")

Comment 14 Hanns-Joachim Uhl 2016-08-27 16:35:27 UTC
Hello Rafael,
... please include the two patches from comment #10 and comment #13 in RHEL7.3 ...
Thanks in advance for your support.

Comment 16 Rafael Fonseca 2016-08-29 12:21:51 UTC
IBM,

unfortunately our QA is out of capacity. However, if you'd be willing to test this, we can still include the patches in RHEL-7.3.

Comment 17 Hanns-Joachim Uhl 2016-08-29 14:28:19 UTC
(In reply to Rafael Fonseca from comment #16)
> IBM,
> 
> unfortunately our QA is out of capacity. However, if you'd be willing to
> test this, we can still include the patches in RHEL-7.3.
.
fyi ... IBM will do fix verification ... setting OtherQA ...

Comment 20 Hanns-Joachim Uhl 2016-09-22 08:46:01 UTC
fyi ... verified with RHEL7.3 Snapshot 4 ... closing ...

Comment 23 errata-xmlrpc 2016-11-04 05:13:06 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2389.html


Note You need to log in before you can comment on or make changes to this bug.