Skip to content

Commit

Permalink
Bug-fix in size calculation
Browse files Browse the repository at this point in the history
Fixes a bug in how PARASITE_MAX_GROUPS was calculated, and adds a
compiler check to assert that parasite_dump_creds doesn't exceed
the page size.

Signed-off-by: Sophie Blee-Goldman <ableegoldman@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
Sophie Blee-Goldman authored and xemul committed Aug 13, 2014
1 parent ded0426 commit 3faaed2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/parasite.h
Expand Up @@ -162,7 +162,12 @@ struct parasite_dump_misc {
int dumpable;
};

#define PARASITE_MAX_GROUPS (PAGE_SIZE / sizeof(unsigned int) - 2 * sizeof(unsigned))
/*
* Calculate how long we can make the groups array in parasite_dump_creds
* and still fit the struct in one page
*/
#define PARASITE_MAX_GROUPS \
((PAGE_SIZE - 2 * sizeof(unsigned int)) / sizeof(unsigned int))

struct parasite_dump_creds {
unsigned int secbits;
Expand Down
2 changes: 2 additions & 0 deletions parasite-syscall.c
Expand Up @@ -735,6 +735,8 @@ int parasite_dump_creds(struct parasite_ctl *ctl, CredsEntry *ce)
{
struct parasite_dump_creds *pc;

BUILD_BUG_ON(sizeof(*pc) > PAGE_SIZE);

pc = parasite_args(ctl, struct parasite_dump_creds);
if (parasite_execute_daemon(PARASITE_CMD_DUMP_CREDS, ctl) < 0)
return -1;
Expand Down

0 comments on commit 3faaed2

Please sign in to comment.