Skip to contentSkip to conversation

dm ioctl: prevent stack leak in dm ioctl call

PATCH Alasdair G Kergon 1 participant 4 messages Apr 26, 2017 – Apr 27, 2017 3 messages not in the archive Device mapper

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Alasdair G Kergon

author maintainer
#1 lore raw
Quoted 3 lines · Adrian Salido

Struct dm_ioctl has some padding/data that is not explicitly cleared before copying to user. This can cause kernel stack contents to be leaked to user space.

Please be more precise here, explaining which part of the buffer and under exactly what circumstances you have found that uninitialised content gets returned to userspace.

Alasdair

A message that is not in the archive (sent off-list or not yet received): CAEP91RFJTRk7Ux3W=1TMfgjzF1cMc5jXF+om4Qchh8RDx84MtQ@mail.gmail.com

author maintainer
#3 lore raw
Quoted 4 lines · Adrian Salido

it's actually the data portion of the struct under a custom user ioctl where (param_kernel->data_size - minimum_data_size) < sizeof(param_kernel->data)
Will update the patch to be clear

Yes - but before updating the patch, we need to be clearer about the requirements of the ioctl here.

Why are two different minimum data sizes used?

If we let userspace send a truncated dm_ioctl struct, why are we not returning the same truncated one?

Is this the bug?
param->data_size = sizeof(*param);

Alasdair

A message that is not in the archive (sent off-list or not yet received): CAEP91RG_9i80LpiGY+qSrcpcOt-F1ziUXAttSX2GUGFMsD8G6g@mail.gmail.com

author maintainer
#5 lore raw
Quoted 5 lines · Adrian Salido

1. param_kernel is allocated from stack and passed to copy_params
2. copy_params only copies up to param_kernel->data from user (param_kernel->data still contains stack contents)
3. in copy_params, since there are no params it will skip through and return param = dmi = param_kernel

after setting
dmi->data_size = minimum_data_size;

and then
input_param_size = param->data_size;

Quoted 1 line

4. that stale data is copied back to user

because it is incorrectly extending the buffer?
param->data_size = sizeof(*param);
instead of continuing to use input_param_size?

Alasdair

author maintainer
#6 lore raw
In reply to a message not in the archive
Quoted 1 line · Adrian Salido

Will update the patch to be clear

So at the moment, we're leaning towards just:

param->data_size = offsetof(struct dm_ioctl, data)

to replace

  param->data_size = sizeof(*param);

in the caller.

Alasdair