From 7a2755a56ff1a9fab7b6166bbaf5d69dd059c472 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 25 Sep 2013 15:57:32 +0200 Subject: [PATCH] light: prevent races on device size --- kernel/sy_old/mars_light.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/sy_old/mars_light.c b/kernel/sy_old/mars_light.c index 3fa31c1b..e7ccca08 100644 --- a/kernel/sy_old/mars_light.c +++ b/kernel/sy_old/mars_light.c @@ -443,8 +443,19 @@ int _set_if_params(struct mars_brick *_brick, void *private) MARS_ERR("bad brick type\n"); return -EINVAL; } - if (rot) - if_brick->dev_size = rot->dev_size; + if (!rot) { + MARS_ERR("too early\n"); + return -EINVAL; + } + if (rot->dev_size <= 0) { + MARS_ERR("dev_size = %lld\n", rot->dev_size); + return -EINVAL; + } + if (if_brick->dev_size > 0 && rot->dev_size < if_brick->dev_size) { + MARS_ERR("new dev size = %lld < old dev_size = %lld\n", rot->dev_size, if_brick->dev_size); + return -EINVAL; + } + if_brick->dev_size = rot->dev_size; if_brick->max_plugged = IF_MAX_PLUGGED; if_brick->readahead = IF_READAHEAD; if_brick->skip_sync = IF_SKIP_SYNC;