develooper Front page | perl.perl5.porters | Postings from July 2012

[perl #113980] [PATCH] pp_syscall: "I32 retval" truncates the returned value

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
July 8, 2012 22:53
Subject:
[perl #113980] [PATCH] pp_syscall: "I32 retval" truncates the returned value
Message ID:
rt-3.6.HEAD-28836-1341813193-1694.113980-15-0@perl.org
On Thu Jul 05 02:15:16 2012, oleg@redhat.com wrote:
> Father,
> 
> I do not know if it is OK to reply to perlbug-followup@perl.org,
> so I CC'ed you explicitly.
> 
> On 07/04, Father Chrysostomos via RT wrote:
> >
> > I don’t supposed it’s possible to
> > write an automated test for this, is it?
> 
> Well, please see below. Not sure it is the best...
> 
> So. The test-case assumes 64-bit linux, otherwise it won't work.
> 
> It exploits the fact that vdso is mmapped at "high" address which
> can't fit in I32.
> 
> It does mremap(vdso_addr, 1, 1, 0) which is "nop" but should return
> the original address.
> 
> Btw, "-w" complains:
> 
> 	Hexadecimal number > 0xffffffff non-portable at ...
> 
> a bit annoying on 64-bit systems... Not sure why Perl_grok_hex()
> thinks this is not portable.
> 
> Oleg.
> 
> -------------------------------------------------------------------
> #!/usr/bin/perl -w
> use strict;
> 
> sub find_vdso()
> {
> 	open my $maps, '<', '/proc/self/maps' or die;
> 	/^(.*?)-.*\[vdso\]$/ and return hex $1 for <$maps>;
> }
> 
> my $vdso_addr = find_vdso || die 'not 64-bit linux?';
> 
> my $ret = syscall 25,		# __NR_mremap
> 		$vdso_addr,	# old_addr
> 		1,		# old_len
> 		1,		# new_len
> 		0,		# flags
> 		0;		# new_addr (unused)
> 
> $ret == $vdso_addr or die "FAILED\n";
> 

Thank you.  I’ll have to adjust this a bit to turn it into a test.  Does
$^O give you ‘linux’?

There is a possibility that another OS might have a plain file called
/proc/self/maps whose contents just happen to match the regular
expression, resulting in an invalid syscall, and perhaps a crash.

So we should skip early if $^O is not appropriate.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113980

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About