login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2010
»
August
»
25
Re: [PATCH v4] 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: [PATCH v4] core_pattern: fix long parameters was truncated by core_pattern handler
Date: Tuesday, August 24, 2010 - 6:58 pm
On 08/25/2010 06:47 AM, Andrew Morton wrote:
quoted text
> On Tue, 24 Aug 2010 17:42:46 +0800 > Xiaotian Feng<dfeng@redhat.com> wrote: > >> 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 v3: >> make handling of single char also uses cn_printf, suggested by Andrew Morton. >> >> Changes since v2: >> Introduced generic function cn_printf and make format_corename remember the time >> has been expanded, suggested by Olg Nesterov and Neil Horman. >> >> Changes since v1: >> This patch allocates corename at runtime, if the replace doesn't have enough >> memory, expand the corename dynamically, suggested by Neil Horman. >> >> I've tested with some core_pattern strings, it works fine now. > > cool, thanks. > >> >> ... >> >> -static int format_corename(char *corename, long signr) >> +static int format_corename(struct core_name *cn, long signr) >> { >> const struct cred *cred = current_cred(); >> const char *pat_ptr = core_pattern; >> int ispipe = (*pat_ptr == '|'); >> - char *out_ptr = corename; >> - char *const out_end = corename + CORENAME_MAX_SIZE; >> - int rc; >> int pid_in_pattern = 0; >> + int err = 0; >> + >> + cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count); >> + cn->corename = kmalloc(cn->size, GFP_KERNEL); >> + cn->used = 0; >> + >> + if (!cn->corename) >> + return -ENOMEM; >> >> /* Repeat as long as we have more pattern to process and more output >> space */ >> while (*pat_ptr) { >> if (*pat_ptr != '%') { >> - if (out_ptr == out_end) >> - goto out; >> - *out_ptr++ = *pat_ptr++; >> + err = cn_printf(cn, "%c", *pat_ptr++); >> } else { >> switch (*++pat_ptr) { >> + /* single % at the end, drop that */ >> case 0: >> + err = cn_printf(cn, "%c", '__PLACEHOLDER__0_'); > > Confused. Doesn't this bit just add another __PLACEHOLDER__0_ to the end of an > already-null-terminated string? And then make cn->used get out of sync > with strlen(cn->corename)? >
Good catch, I just realized the return value of vsnprintf is not including the trailing '\0', will follow an updated v5 patch. Thanks Andrew. --
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
Create content
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Eric Sandeen
Re: [PATCH] xfs: do not pass unused params to xfs_flush_pages
Daniel Hazelton
Re: x86: 4kstacks default
Mathieu Desnoyers
Re: Linux 2.6.25-rc2
Alexey Dobriyan
Re: [2.6.22.2 review 09/84] Fix rfkill IRQ flags.
Alexandre Oliva
Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3
git
:
Felipe Contreras
Re: [kernel.org users] [RFD] On deprecating "git-foo" for builtins
Johannes Schindelin
[PATCH] fetch: refuse to fetch into the current branch in a non-bare repository
Johannes Schindelin
Re: [PATCH] Fix install-doc-quick target
Nicolas Pitre
Re: About git and the use of SHA-1
Alex Riesen
Re: git exclude patterns for directory
linux-netdev
:
Andi Kleen
Re: RFC: Nagle latency tuning
Herbert Xu
Re: Oops in tun: bisected to Limit amount of queued packets per device
gregkh
Patch "IPv6: keep route for tentative address" has been added to the 2.6.34-stable...
Patrick McHardy
Re: [rfc 02/13] [RFC 02/13] netfilter: nf_conntrack_sip: Add callid parser
Paul Gortmaker
[PATCH net-next 09/16] tipc: Relocate trivial link status functions to header file
git-commits-head
:
Linux Kernel Mailing List
sh: Fix compile error by operands(mov.l) in sh3/entry.S
Linux Kernel Mailing List
New device ID for sc92031 [1088:2031]
Linux Kernel Mailing List
tmpfs: depend on shmem
Linux Kernel Mailing List
drivers/acpi: use kasprintf
Linux Kernel Mailing List
Staging: et131x: prune all the debug code
openbsd-misc
:
Andres Salazar
About priorities in /etc/resolv.conf
Tonnerre LOMBARD
Re: bge0: watchdog timeout
Rob Shepherd
x86 hardware for router system
Damien Miller
Re: Patching a SSH 'Weakness'
ropers
Re: Real men don't attack straw men
Colocation donated by:
Syndicate