From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mickerik.phytec.de ([195.145.39.210]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hT600-0007Gd-PF for barebox@lists.infradead.org; Tue, 21 May 2019 14:44:18 +0000 From: Jan Remmet Date: Tue, 21 May 2019 16:44:13 +0200 Message-Id: <1558449853-28519-1-git-send-email-j.remmet@phytec.de> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH] common: state: check length To: barebox@lists.infradead.org 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. Signed-off-by: Jan Remmet --- common/state/backend_bucket_direct.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 95ddb9310685..fc633eea8dec 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -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; -- 2.7.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox