common: state: check length
PATCH 1/1 common: state: check length
if written_length is read from a partial written bucket it may be to big and xmalloc will panic barebox.
Check if the value is sane.
--- common/state/backend_bucket_direct.c | 4 ++++ 1 file changed, 4 insertions(+)
common/state/backend_bucket_direct.c +4 -0
@@ -67,6 +67,10 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket }if (meta.magic == direct_magic) { read_len = meta.written_length; +if (read_len <0 || read_len > direct->max_size) { +dev_err (direct->dev,"Wrong length in meta data\n" ); +return -EINVAL ; + } }else {if (meta.magic != ~0 && !!meta.magic) bucket->wrong_magic =1 ;
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 15 lines · Jan Remmet
if
written_lengthis read from a partial written bucket it may be to big and xmalloc will panic barebox.Check if the value is sane.
Signed-off-by Jan Remmet <[email protected]>--- common/state/backend_bucket_direct.c | 4 ++++ 1 file changed, 4 insertions(+)common/state/backend_bucket_direct.c +0
-0
common/state/backend_bucket_direct.c static int state_backend_bucket_direct_read(struct state_backend_storage_bucket · line 70
Quoted 4 lines
common/state/backend_bucket_direct.c +1
-0@@ -67,6 +67,10 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket }if (meta.magic == direct_magic) { read_len = meta.written_length; +if (read_len <0 || read_len > direct->max_size) {
written_length in struct state_backend_storage_bucket_direct_meta is unsigned and so should be read_len. Then you can skip the read_len < 0 check.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/1 common: state: check length
if written_length is read from a partial written bucket it may be to big and xmalloc will panic barebox.
Check if the value is sane. Make read_len unsigned to avoid negative values.
---
v2: replace compare < 0 by making read_len unsigned
common/state/backend_bucket_direct.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
common/state/backend_bucket_direct.c +6 -1
@@ -52,7 +52,7 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucketstruct state_backend_storage_bucket_direct *direct =get_bucket_direct (bucket);struct state_backend_storage_bucket_direct_meta meta; -ssize_t read_len; +uint32_t read_len;void *buf;int ret;
@@ -67,6 +67,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket }if (meta.magic == direct_magic) { read_len = meta.written_length; +if (read_len > direct->max_size) { +dev_err (direct->dev,"Wrong length in meta data\n" ); +return -EINVAL ; + + } }else {if (meta.magic != ~0 && !!meta.magic) bucket->wrong_magic =1 ;
Signature · 7 lines
2.7.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 9 lines · Jan Remmet
if
written_lengthis read from a partial written bucket it may be to big and xmalloc will panic barebox.Check if the value is sane. Make
read_lenunsigned to avoid negative values.Signed-off-by Jan Remmet <[email protected]>---
v2: replace compare < 0 by makingread_lenunsigned
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox