Re: [PATCH] IPVS: replace sprintf to snprintf to avoid stack buffer over

To: Changli Gao <xiaosuo@xxxxxxxxx>
Subject: Re: [PATCH] IPVS: replace sprintf to snprintf to avoid stack buffer overflow
Cc: wzt.wzt@xxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, wensong@xxxxxxxxxxxx, Julian Anastasov <ja@xxxxxx>, netdev@xxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, Patrick McHardy <kaber@xxxxxxxxx>
From: Simon Horman <horms@xxxxxxxxxxxx>
Date: Tue, 6 Apr 2010 13:26:42 +1000
On Tue, Apr 06, 2010 at 10:58:28AM +0800, Changli Gao wrote:
> On Tue, Apr 6, 2010 at 10:50 AM,  <wzt.wzt@xxxxxxxxx> wrote:
> > IPVS not check the length of pp->name, use sprintf will cause stack buffer 
> > overflow.
> > struct ip_vs_protocol{} declare name as char *, if register a protocol as:
> > struct ip_vs_protocol ip_vs_test = {
> >        .name =                 "",
> >        .debug_packet =         ip_vs_tcpudp_debug_packet,
> > };
> >
> > when called ip_vs_tcpudp_debug_packet(), sprintf(buf, "%s TRUNCATED", 
> > pp->name);
> > will cause stack buffer overflow.
> >
> Long messages will be truncated instead of buffer overflow. We need to
> find a way to handle long messages elegantly.

Its really a corner case. In practice protocol modules don't have really
long names. And if one was merged that did, the buffer size could be increased
at that time.

So while I think its reasonable to protect against something unexpected
in a protocol-module name crashing the system. Especially as that
can be achieved without any real overhead. I don't think we need
to sanitise the output.
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

<Prev in Thread] Current Thread [Next in Thread>