From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757994Ab0FOOyg (ORCPT ); Tue, 15 Jun 2010 10:54:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49269 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756270Ab0FOOye (ORCPT ); Tue, 15 Jun 2010 10:54:34 -0400 Subject: Re: [PATCH v2] trace-cmd: prevent print_graph_duration buffer overflow From: Steven Rostedt To: Chase Douglas Cc: Valdis.Kletnieks@vt.edu, Frederic Weisbecker , linux-kernel@vger.kernel.org In-Reply-To: <1276613224-19247-1-git-send-email-chase.douglas@canonical.com> References: <1276613224-19247-1-git-send-email-chase.douglas@canonical.com> Content-Type: text/plain Organization: Red Hat Date: Tue, 15 Jun 2010 10:54:21 -0400 Message-Id: <1276613661.13426.56.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quick note. Please send to my rostedt@goodmis.org address. I may not see messages here for weeks at a time. I author patches with my RH account just to "advertise" who I work for. But I sign-off-by with the account I want people to send to. On Tue, 2010-06-15 at 10:47 -0400, Chase Douglas wrote: > Passing n > sizeof(string) to snprintf can cause a glibc buffer overflow > condition. We know the exact size of nsecs_str, so use it along with the > the math to determine the longest string size we want. > > Note that an overflow isn't really possible given the format of the > string. However, glibc would abort due to a runtime check. > > Signed-off-by: Chase Douglas Thanks! Can you write a similar patch for the Linux kernel too. It may need to go to stable as well. -- Steve > --- > trace-ftrace.c | 3 ++- > 1 files changed, 2 insertions(+), 1 deletions(-) > > diff --git a/trace-ftrace.c b/trace-ftrace.c > index af9ac8d..181a00f 100644 > --- a/trace-ftrace.c > +++ b/trace-ftrace.c > @@ -21,6 +21,7 @@ > #include > #include > #include > +#include > > #include "trace-cmd.h" > > @@ -148,7 +149,7 @@ static void print_graph_duration(struct trace_seq *s, unsigned long long duratio > > /* Print nsecs (we don't want to exceed 7 numbers) */ > if ((s->len - len) < 7) { > - snprintf(nsecs_str, 8 - (s->len - len), "%03lu", nsecs_rem); > + snprintf(nsecs_str, MIN(sizeof(nsecs_str), 8 - len), "%03lu", nsecs_rem); > trace_seq_printf(s, ".%s", nsecs_str); > } >