Commit 3faaed2f authored by Sophie Blee-Goldman's avatar Sophie Blee-Goldman Committed by Pavel Emelyanov

Bug-fix in size calculation

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: 's avatarSophie Blee-Goldman <ableegoldman@google.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ded04267
...@@ -162,7 +162,12 @@ struct parasite_dump_misc { ...@@ -162,7 +162,12 @@ struct parasite_dump_misc {
int dumpable; 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 { struct parasite_dump_creds {
unsigned int secbits; unsigned int secbits;
......
...@@ -735,6 +735,8 @@ int parasite_dump_creds(struct parasite_ctl *ctl, CredsEntry *ce) ...@@ -735,6 +735,8 @@ int parasite_dump_creds(struct parasite_ctl *ctl, CredsEntry *ce)
{ {
struct parasite_dump_creds *pc; struct parasite_dump_creds *pc;
BUILD_BUG_ON(sizeof(*pc) > PAGE_SIZE);
pc = parasite_args(ctl, struct parasite_dump_creds); pc = parasite_args(ctl, struct parasite_dump_creds);
if (parasite_execute_daemon(PARASITE_CMD_DUMP_CREDS, ctl) < 0) if (parasite_execute_daemon(PARASITE_CMD_DUMP_CREDS, ctl) < 0)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment