Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

delayacct: align to 8 byte boundary on 64-bit systems

prepare_reply() sets up an skb for the response. The payload contains:

+--------------------------------+
| genlmsghdr - 4 bytes |
+--------------------------------+
| NLA header - 4 bytes | /* Aggregate header */
+-+------------------------------+
| | NLA header - 4 bytes | /* PID header */
| +------------------------------+
| | pid/tgid - 4 bytes |
| +------------------------------+
| | NLA header - 4 bytes | /* stats header */
| + -----------------------------+ <- oops. aligned on 4 byte boundary
| | struct taskstats - 328 bytes |
+-+------------------------------+

The start of the taskstats struct must be 8 byte aligned on IA64 (and
other systems with 8 byte alignment rules for 64-bit types) or runtime
alignment warnings will be issued.

This patch pads the pid/tgid field out to sizeof(long), which forces the
alignment of taskstats. The getdelays userspace code is ok with this
since it assumes 32-bit pid/tgid and then honors that header's length
field.

An array is used to avoid exposing kernel memory contents to userspace in
the response.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jeff Mahoney and committed by
Linus Torvalds
85893120 db9e5679

+7 -1
+7 -1
kernel/taskstats.c
··· 360 360 struct nlattr *na, *ret; 361 361 int aggr; 362 362 363 + /* If we don't pad, we end up with alignment on a 4 byte boundary. 364 + * This causes lots of runtime warnings on systems requiring 8 byte 365 + * alignment */ 366 + u32 pids[2] = { pid, 0 }; 367 + int pid_size = ALIGN(sizeof(pid), sizeof(long)); 368 + 363 369 aggr = (type == TASKSTATS_TYPE_PID) 364 370 ? TASKSTATS_TYPE_AGGR_PID 365 371 : TASKSTATS_TYPE_AGGR_TGID; ··· 373 367 na = nla_nest_start(skb, aggr); 374 368 if (!na) 375 369 goto err; 376 - if (nla_put(skb, type, sizeof(pid), &pid) < 0) 370 + if (nla_put(skb, type, pid_size, pids) < 0) 377 371 goto err; 378 372 ret = nla_reserve(skb, TASKSTATS_TYPE_STATS, sizeof(struct taskstats)); 379 373 if (!ret)