From: Laszlo Ersek <lersek@redhat.com>
To: David Vrabel <david.vrabel@citrix.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: x86@kernel.org, Andrew Jones <drjones@redhat.com>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
xen-devel@lists.xenproject.org,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [Xen-devel] [PATCH] x86/xen: avoid freeing static 'name' when kasprintf() fails
Date: Mon, 05 Jan 2015 14:58:28 +0100 [thread overview]
Message-ID: <54AA9884.5070202@redhat.com> (raw)
In-Reply-To: <54AA8F7C.6000006@citrix.com>
On 01/05/15 14:19, David Vrabel wrote:
> On 05/01/15 13:06, Vitaly Kuznetsov wrote:
>> In case kasprintf() fails in xen_setup_timer() we assign name to the static
>> string "<timer kasprintf failed>". We, however, don't check that fact before
>> issuing kfree() in xen_teardown_timer(), kernel is supposed to crash with
>> 'kernel BUG at mm/slub.c:3341!'
>>
>> Solve the issue by making name a fixed length string inside struct
>> xen_clock_event_device. 16 bytes should be enough.
>>
>> The issue was discovered by Laszlo Ersek.
>
> Add Reported-by: Laszlo ... tag perhaps?
>
>> --- a/arch/x86/xen/time.c
>> +++ b/arch/x86/xen/time.c
>> @@ -391,7 +391,7 @@ static const struct clock_event_device *xen_clockevent =
>>
>> struct xen_clock_event_device {
>> struct clock_event_device evt;
>> - char *name;
>> + char name[16];
>> };
>> static DEFINE_PER_CPU(struct xen_clock_event_device, xen_clock_events) = { .evt.irq = -1 };
>>
>> @@ -420,14 +420,11 @@ void xen_teardown_timer(int cpu)
>> if (evt->irq >= 0) {
>> unbind_from_irqhandler(evt->irq, NULL);
>> evt->irq = -1;
>> - kfree(per_cpu(xen_clock_events, cpu).name);
>> - per_cpu(xen_clock_events, cpu).name = NULL;
>> }
>> }
>>
>> void xen_setup_timer(int cpu)
>> {
>> - char *name;
>> struct clock_event_device *evt;
>
> struct xen_clock_event_device *xevt = ...;
>
>> int irq;
>>
>> @@ -438,21 +435,19 @@ void xen_setup_timer(int cpu)
>>
>> printk(KERN_INFO "installing Xen timer for CPU %d\n", cpu);
>>
>> - name = kasprintf(GFP_KERNEL, "timer%d", cpu);
>> - if (!name)
>> - name = "<timer kasprintf failed>";
>> + snprintf(per_cpu(xen_clock_events, cpu).name, 16, "timer%d", cpu);
>
> Use sizeof(xevt->name) here.
Yes, I wanted to recommend sizeof too.
Also the "standard" Reported-by tag would be nice.
Thanks!
Laszlo
next prev parent reply other threads:[~2015-01-05 13:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-05 13:06 [PATCH] x86/xen: avoid freeing static 'name' when kasprintf() fails Vitaly Kuznetsov
2015-01-05 13:19 ` David Vrabel
2015-01-05 13:19 ` [Xen-devel] " David Vrabel
2015-01-05 13:58 ` Laszlo Ersek [this message]
2015-01-05 13:58 ` Laszlo Ersek
2015-01-05 15:27 ` [PATCH v2] " Vitaly Kuznetsov
2015-01-05 15:27 ` Vitaly Kuznetsov
2015-01-05 15:36 ` Laszlo Ersek
2015-01-05 15:36 ` Laszlo Ersek
2015-01-08 14:36 ` [Xen-devel] " David Vrabel
2015-01-08 14:36 ` David Vrabel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54AA9884.5070202@redhat.com \
--to=lersek@redhat.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=drjones@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.