2007-01-05 16:39:04

by Bodo Eggert

[permalink] [raw]
Subject: Re: [UPDATED PATCH] fix memory corruption from misinterpreted bad_inode_ops return values

Eric Sandeen <[email protected]> wrote:
> Andrew Morton wrote:

>> +++ a/fs/bad_inode.c

>> -static int return_EIO(void)
>> +static long return_EIO(void)

> What about ops that return loff_t (64 bits) on 32-bit arches and stuff
> it into 2 registers....

*If* it uses an additional register for the high bits, it will set e.g.:
EDX << 32 | EAX == (s64) -EIO
and therefore
EAX == -EIO // < -MAXLONGINT-1
EDX == -1

EAX will be the return register for s32. Therefore you can use one function
for both cases on i386:

long long f()
{
return -42;
}

long (*l )() = (void*)f; // hide warning
long long (*ll)() = f;

int main(){
printf("%ld %lld\n", l(), ll());
}

> I'm still not convinced that this is the best place to be clever :)

ACK, not too clever, but not too stupid, too. Having #ifdef I386 etc.
isn't nice, and something like this shouldn't be arch-specific.
OTOH, C calling convention allows having a different argument signature,
so you can safely use it. It's a feature.
--
Ich danke GMX daf?r, die Verwendung meiner Adressen mittels per SPF
verbreiteten L?gen zu sabotieren.

http://david.woodhou.se/why-not-spf.html