lkml.org 
[lkml]   [2008]   [May]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: capget() overflows buffers.
* Bojan Smojver (bojan@rexursive.com) wrote:
> On Thu, 2008-05-22 at 13:53 -0700, Chris Wright wrote:
>
> > cap_user_header_t head = (cap_user_header_t) xcalloc(1, sizeof(cap_user_header_t));
> > cap_user_data_t cap = (cap_user_data_t) xcalloc(1, sizeof(cap_user_data_t));
>
> BTW, both of the above allocations have been fixed in Squid 2 & 3, as
> they were incorrect. Not sure how that worked before - probably by
> accident.

Heh, indeed ;-)

If you want to fix the problem you're having in squid you've got a few
choices:

1) switch to using the libcap interface, arguably the best sol'n since
you know longer have to directly care about the kernel interface.
only drawback is the additional library dependency.

2) force head->version to the older version, something like:

#ifdef _LINUX_CAPABILITY_VERSION_1
head->version = _LINUX_CAPABILITY_VERSION_1;
#else
head->version = _LINUX_CAPABILITY_VERSION;
#endif

this has the drawback of always using the older 32bit caps, probably
fine here, since you're not using new caps.

3) try to allow for current 64bit caps

#define CAP_TO_INDEX(x) ((x) >> 5)
#define CAP_TO_MASK(x) (1 << ((x) & 31))
#define CAP_ADD(_data, _set, _cap) _data[CAP_TO_INDEX(_cap)]._set |= CAP_TO_MASK(_cap)

cap_user_data_t cap = (cap_user_data_t) xcalloc(_LINUX_CAPABILITY_U32S, sizeof(*cap));
head->version = _LINUX_CAPABILITY_VERSION;

CAP_ADD(cap, effective, CAP_NET_BIND_SERVICE);
etc...

this has the drawback of not being guaranteed to work in the future on
newer kernels and needs ifdefs to work on older kernels, is complicated,
and not worth it.


\
 
 \ /
  Last update: 2008-05-23 04:09    [W:0.093 / U:5.828 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site