Skip to content

Commit b60528d

Browse files
DemiMarieMike Snitzer
authored andcommitted
dm ioctl: Check dm_target_spec is sufficiently aligned
Otherwise subsequent code, if given malformed input, could dereference a misaligned 'struct dm_target_spec *'. Signed-off-by: Demi Marie Obenour <[email protected]> Signed-off-by: Stephen Rothwell <[email protected]> # use %zu Reviewed-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 2971c05 commit b60528d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/md/dm-ioctl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,15 @@ static inline blk_mode_t get_mode(struct dm_ioctl *param)
13941394
static int next_target(struct dm_target_spec *last, uint32_t next, void *end,
13951395
struct dm_target_spec **spec, char **target_params)
13961396
{
1397+
static_assert(__alignof__(struct dm_target_spec) <= 8,
1398+
"struct dm_target_spec must not require more than 8-byte alignment");
1399+
1400+
if (next % __alignof__(struct dm_target_spec)) {
1401+
DMERR("Next dm_target_spec (offset %u) is not %zu-byte aligned",
1402+
next, __alignof__(struct dm_target_spec));
1403+
return -EINVAL;
1404+
}
1405+
13971406
*spec = (struct dm_target_spec *) ((unsigned char *) last + next);
13981407
*target_params = (char *) (*spec + 1);
13991408

0 commit comments

Comments
 (0)