Re: capget() overflows buffers.

From: Chris Wright
Date: Thu May 22 2008 - 22:07:18 EST

* Bojan Smojver (bojan@xxxxxxxxxxxxx) 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

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:

head->version = _LINUX_CAPABILITY_VERSION_1;

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));

CAP_ADD(cap, effective, CAP_NET_BIND_SERVICE);

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.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at