oss-sec mailing list archives
Re: Interesting behavior with struct initiailization
From: Bhadrinath <bitstrat () gmail com>
Date: Sun, 5 Dec 2010 18:58:07 +0000 (UTC)
One solution that could ensure no padding bits are copied uninitialized,
*******************************************************************************
struct test{ int a; char b; int c;};
// Let arg be the one to be copied into user space
struct test arg = { .a = 1, .b = 2, .c = 3 };
// Create an equivalent structure
struct test argC;
.
.
.
// Do all the operations on arg and just before passing it to the function
// clear the argC to zero
memset_s(&argC, 0,sizeof argC);
// Now copy the contents of arg into argC one by one
memcpy(&argC.a,&arg.a,sizeof arg.a);
memcpy(&argC.b,&arg.b,sizeof arg.b);
memcpy(&argC.c,&arg.c,sizeof arg.c);
//This ensures that no uninitialized padding bits are passed to the user space
copy_to_user(ptr,&argC,sizeof argC);
*******************************************************************************
Comments and other ideas are welcome.
Regards
Bhadrinath
Current thread:
- Re: Interesting behavior with struct initiailization Geoff Keating (Nov 29)
- RE: Interesting behavior with struct initiailization Robert Seacord (Dec 03)
- Re: Interesting behavior with struct initiailization Geoff Keating (Dec 03)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Re: Interesting behavior with struct initiailization Dan Rosenberg (Dec 05)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Interesting behavior with struct initiailization Geoff Keating (Dec 03)
- RE: Interesting behavior with struct initiailization Robert Seacord (Dec 03)
