From: Andrew Morton <akpm@linux-foundation.org>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [PATCH] Fix bufferoverflow and races in capi debug
Date: Mon, 26 Feb 2007 11:52:58 +0000 [thread overview]
Message-ID: <20070226035258.d34cb3d2.akpm@linux-foundation.org> (raw)
In-Reply-To: <20070225184951.GA8615@pingi.kke.suse.de>
(cc's restored. Please don't do that).
> On Mon, 26 Feb 2007 09:15:18 +0100 walter harms <wharms@bfs.de> wrote:
>
> this reminds me of the glibc asprint() funktion. IMHO it would be useful to have this
> as kernelfunction, because printing in a buffer for e.g. for proc and friends is commen.
>
We already have kasprintf() and I suspect this patch should be using it.
>
> re,
> wh
>
> Karsten Keil wrote:
> > The CAPI trace debug functions were using a fixed size buffer, which can be
> > overflowed if wrong formatted CAPI messages were sent to the kernel capi
> > layer. The code was also not protected against multiple callers.
> > This fix bug 8028.
> > Additional the patch make the CAPI trace functions optional.
> >
> > Signed-off-by: Karsten Keil <kkeil@suse.de>
> >
> >
> > #include <stdarg.h>
> >
> > /*-------------------------------------------------------*/
> > -static void bufprint(char *fmt,...)
> > +static _cdebbuf *bufprint(_cdebbuf *cdb, char *fmt,...)
> > {
> > va_list f;
> > + size_t n,r;
> > +
> > + if (!cdb)
> > + return NULL;
> > va_start(f, fmt);
> > - vsprintf(p, fmt, f);
> > + r = cdb->size - cdb->pos;
> > + n = vsnprintf(cdb->p, r, fmt, f);
> > va_end(f);
> > - p += strlen(p);
> > + if (n >= r) {
> > + /* truncated, need bigger buffer */
> > + size_t ns = 2 * cdb->size;
> > + u_char *nb;
> > +
> > + while ((ns - cdb->pos) <= n)
> > + ns *= 2;
> > + nb = kmalloc(ns, GFP_ATOMIC);
> > + if (!nb) {
> > + cdebbuf_free(cdb);
> > + return NULL;
> > + }
> > + memcpy(nb, cdb->buf, cdb->pos);
> > + kfree(cdb->buf);
> > + nb[cdb->pos] = 0;
> > + cdb->buf = nb;
> > + cdb->p = cdb->buf + cdb->pos;
> > + cdb->size = ns;
> > + va_start(f, fmt);
> > + r = cdb->size - cdb->pos;
> > + n = vsnprintf(cdb->p, r, fmt, f);
> > + va_end(f);
> > + }
> > + cdb->p += n;
> > + cdb->pos += n;
> > + return cdb;
> > }
> >
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
next prev parent reply other threads:[~2007-02-26 11:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-25 18:49 [KJ] [PATCH] Fix bufferoverflow and races in capi debug functions Karsten Keil
2007-02-26 8:15 ` [KJ] [PATCH] Fix bufferoverflow and races in capi debug walter harms
2007-02-26 11:52 ` Andrew Morton [this message]
2007-02-26 12:58 ` Karsten Keil
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=20070226035258.d34cb3d2.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=kernel-janitors@vger.kernel.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.