login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2010
»
August
»
20
Re: [RFC PATCH v3] core_pattern: fix long parameters was truncated by core_pattern handler
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: Xiaotian Feng
Subject:
Re: [RFC PATCH v3] core_pattern: fix long parameters was truncated by core_pattern handler
Date: Friday, August 20, 2010 - 2:35 am
On 08/20/2010 05:22 PM, Xiaotian Feng wrote:
quoted text
> We met a parameter truncated issue, consider following: >> echo "|/root/core_pattern_pipe_test %p /usr/libexec/blah-blah-blah \ > %s %c %p %u %g 11 12345678901234567890123456789012345678 %t"> \ > /proc/sys/kernel/core_pattern > > This is okay because the strings is less than CORENAME_MAX_SIZE. > "cat /proc/sys/kernel/core_pattern" shows the whole string. but > after we run core_pattern_pipe_test in man page, we found last > parameter was truncated like below: > argc[10]=<12807486> > > The root cause is core_pattern allows % specifiers, which need to be > replaced during parse time, but the replace may expand the strings > to larger than CORENAME_MAX_SIZE. So if the last parameter is % > specifiers, the replace code is using snprintf(out_ptr, out_end - out_ptr, ...), > this will write out of corename array. > > Changes since v2: > Introduced generic function cn_printf and make format_corename remember the time > has been expanded. > > Changes since v1: > This patch allocates corename at runtime, if the replace doesn't have enough > memory, expand the corename dynamically. > > Signed-off-by: Xiaotian Feng<dfeng@redhat.com> > Cc: Alexander Viro<viro@zeniv.linux.org.uk> > Cc: Andrew Morton<akpm@linux-foundation.org> > Cc: Oleg Nesterov<oleg@redhat.com> > Cc: KOSAKI Motohiro<kosaki.motohiro@jp.fujitsu.com> > Cc: Neil Horman<nhorman@tuxdriver.com> > Cc: Roland McGrath<roland@redhat.com> > --- > fs/exec.c | 181 +++++++++++++++++++++++++++++++++++++++++-------------------- > 1 files changed, 121 insertions(+), 60 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index 2d94552..e2fe568 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -65,6 +65,12 @@ char core_pattern[CORENAME_MAX_SIZE] = "core"; > unsigned int core_pipe_limit; > int suid_dumpable = 0; > > +struct core_name { > + char *corename; > + int used, size; > +}; > +static atomic_t call_count = ATOMIC_INIT(1); > + > /* The maximal length of core_pattern is also specified in sysctl.c */ > > static LIST_HEAD(formats); > @@ -1440,106 +1446,147 @@ void set_binfmt(struct linux_binfmt *new) > > EXPORT_SYMBOL(set_binfmt); > > +static int expand_corename(struct core_name *cn) > +{ > + char *old_corename = cn->corename; > + > + cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count); > + cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL); > + > + if (!cn->corename) { > + kfree(old_corename); > + return -ENOMEM; > + } > + > + return 0; > +} > + > +static int cn_printf(struct core_name *cn, const char *fmt, ...) > +{ > + char *cur; > + int need; > + int ret; > + va_list arg; > + > + cur = cn->corename + cn->used; > + > + va_start(arg, fmt); > + need = vsnprintf(NULL, 0, fmt, arg); > + va_end(arg); > + > + if (likely(need< cn->size - cn->used)) > + goto out_printf; > + > + ret = expand_corename(cn); > + if (ret) > + goto expand_fail; > + > +out_printf: > + va_start(arg, fmt); > + vsnprintf(cur, need + 1, fmt, arg); > + va_end(arg); > + cn->used += need; > + return 0; > + > +expand_fail: > + va_end(arg);
oops, this line should be removed, please ignore this mail, I'll send an updated patch. Thanks Xiaotian --
unsubscribe notice
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to
majordomo@vger.kernel.org
More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at
http://www.tux.org/lkml/
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
[RFC PATCH] core_pattern: fix long parameters was truncate ...
, Xiaotian Feng
, (Thu Jul 29, 5:42 am)
Re: [RFC PATCH] core_pattern: fix long parameters was trun ...
, Neil Horman
, (Thu Jul 29, 6:31 am)
Re: [RFC PATCH V2] core_pattern: fix long parameters was t ...
, Oleg Nesterov
, (Mon Aug 2, 6:50 am)
Re: [RFC PATCH V2] core_pattern: fix long parameters was t ...
, Neil Horman
, (Tue Aug 3, 3:59 am)
[RFC PATCH v3] core_pattern: fix long parameters was trunc ...
, Xiaotian Feng
, (Fri Aug 20, 2:22 am)
Re: [RFC PATCH v3] core_pattern: fix long parameters was t ...
, Xiaotian Feng
, (Fri Aug 20, 2:35 am)
[RFC PATCH v3] core_pattern: fix long parameters was trunc ...
, Xiaotian Feng
, (Fri Aug 20, 2:35 am)
Re: [RFC PATCH v3] core_pattern: fix long parameters was t ...
, Neil Horman
, (Mon Aug 23, 4:07 am)
Re: [RFC PATCH v3] core_pattern: fix long parameters was t ...
, Andrew Morton
, (Mon Aug 23, 2:18 pm)
Re: [RFC PATCH v3] core_pattern: fix long parameters was t ...
, KOSAKI Motohiro
, (Mon Aug 23, 4:02 pm)
Re: [RFC PATCH v3] core_pattern: fix long parameters was t ...
, Xiaotian Feng
, (Mon Aug 23, 11:18 pm)
[PATCH v4] core_pattern: fix long parameters was truncated ...
, Xiaotian Feng
, (Tue Aug 24, 2:42 am)
Re: [PATCH v4] core_pattern: fix long parameters was trunc ...
, Andrew Morton
, (Tue Aug 24, 3:47 pm)
Re: [PATCH v4] core_pattern: fix long parameters was trunc ...
, Xiaotian Feng
, (Tue Aug 24, 6:58 pm)
[PATCH v5] core_pattern: fix long parameters was truncated ...
, Xiaotian Feng
, (Tue Aug 24, 7:17 pm)
Navigation
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Paul Turner
[tg_shares_up rewrite v4 11/11] sched: update tg->shares after cpu.shares write
Matthew Garrett
Re: [PATCH] Enable speedstep for sonoma processors.
Mauro Carvalho Chehab
Re: [PATCH 1/2] media: Add timberdale video-in driver
Peter Zijlstra
[PATCH 23/30] netvm: skb processing
Greg Kroah-Hartman
[PATCH 21/28] cgroupfs: create /sys/fs/cgroup to mount cgroupfs on
git
:
Jan Hudec
Re: GIT push to sftp (feature request)
Steffen Prohaska
[PATCH 0/4] core.ignorecase
Johannes Schindelin
Re: Git checkout preserve timestamp?
Linus Torvalds
[PATCH 1/7] Make unpack_trees_options bit flags actual bitfields
Johan Herland
Re: What's cooking in git.git (Oct 2010, #01; Wed, 13)
linux-netdev
:
David Miller
Re: [PATCH 1/3] f_phonet: dev_kfree_skb instead of dev_kfree_skb_any in TX callback
Richard Cochran
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Jan Engelhardt
Re: [PATCH] Fix netfilter xt_time's time_mt()'s use of do_div()
Herbert Xu
Re: [RFC PATCH 00/17] virtual-bus
Jeff Kirsher
Re: [net-next-2.6 PATCH] e1000e: don't inadvertently re-set INTX_DISABLE
git-commits-head
:
Linux Kernel Mailing List
ALSA: hda - Enable beep on Realtek codecs with PCI SSID override
Linux Kernel Mailing List
Use path_put() in a few places instead of {mnt,d}put()
Linux Kernel Mailing List
mv643xx_eth: use sw csum for big packets
Linux Kernel Mailing List
arm: fix HAVE_CLK merge goof
Linux Kernel Mailing List
arm: convert pcm037 platform to use smsc911x
freebsd-current
:
David Wolfskill
"interrupt storm..."; seems associated with an0 NIC
Andriy Gapon
Re: letting glabel recognise a media change
Garrett Cooper
Re: Only display ACPI bootmenu key if ACPI is present
Pyun YongHyeon
CFT: msk(4) Rx checksum offloading support
FreeBSD Tinderbox
[head tinderbox] failure on sparc64/sparc64
Colocation donated by:
Syndicate