[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/7] xz: validate the value before assigning it to an enum variable
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Fri, 19 Nov 2021 11:23:31 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s9lhd4h+5NCuGWKWiKjPu07VXVlsfujEz5D+3IHDPrs=; b=S/b4mYP2+fMjHu7DSlaNcX7nxPIL+UNBg+xkH1hnrNFHGXclmy1/kaqcpM0Wr+Jml2i+sGOsXLl0vgXeaTNMK7ehi5dvfOPGex4KTONl5hXaOUibaXs+G839ZEzUoOkI/Z7AoGT7Yh6Q72I4+myfNow0hmQl3PrH/20Y1xSAGY3ru3aG8HzsIdlw/KtnMLY8kdfXd9Pe/PNYRvLpPhDZG6nYKX9C7Of2erEYfUOFhCGVmHSavRl6B364q8ZtCpgTxA4PEKo0ADd6LmyoeuBj9AmpVqFizrATEgSO7VsmYPdk5Pdf7f1DesBJ/xAZ+UllQDaAAjdQ89iINln/GoEmpg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGFx1LVdpmNl+Jq2QE1XbnjByd6FLV+2KG8l93sLFRUiRSuY27yAzBNBziu4xj6chy3HcFtSSMljcR39DgpljkPsRLGnbcNvUZIezT6ebuj/2EsNF6gDsd22ROrLUrpHLHUtuTPXuM2A5f+7CfJjrDvbkQ9lWR9pfa67GsVvb6AFqEgJXuNFROSe0sGyb9DDwwdu5HVRPGZtNLihcMAJLKx++L1E946DCCeYn/STJp/QCu1mNrEGiStkti0iRWqPEpozjkTLzFwiuTA6kzuRFik7+ZyNbMYgccywCRwP1cHXv7SiwFVRlGLIbQc02HHZSwAfQAWigo5B5EcsXVbbgw==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Fri, 19 Nov 2021 10:26:57 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
From: Lasse Collin <lasse.collin@xxxxxxxxxxx>
This might matter, for example, if the underlying type of enum xz_check
was a signed char. In such a case the validation wouldn't have caught an
unsupported header. I don't know if this problem can occur in the kernel
on any arch but it's still good to fix it because some people might copy
the XZ code to their own projects from Linux instead of the upstream
XZ Embedded repository.
This change may increase the code size by a few bytes. An alternative
would have been to use an unsigned int instead of enum xz_check but
using an enumeration looks cleaner.
Link: https://lore.kernel.org/r/20211010213145.17462-3-xiang@xxxxxxxxxx
Signed-off-by: Lasse Collin <lasse.collin@xxxxxxxxxxx>
[Linux commit: 4f8d7abaa413c34da9d751289849dbfb7c977d05]
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
--- a/xen/common/xz/dec_stream.c
+++ b/xen/common/xz/dec_stream.c
@@ -402,12 +402,12 @@ static enum xz_ret __init dec_stream_hea
* we will accept other check types too, but then the check won't
* be verified and a warning (XZ_UNSUPPORTED_CHECK) will be given.
*/
+ if (s->temp.buf[HEADER_MAGIC_SIZE + 1] > XZ_CHECK_MAX)
+ return XZ_OPTIONS_ERROR;
+
s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
#ifdef XZ_DEC_ANY_CHECK
- if (s->check_type > XZ_CHECK_MAX)
- return XZ_OPTIONS_ERROR;
-
if (s->check_type > XZ_CHECK_CRC32)
return XZ_UNSUPPORTED_CHECK;
#else
|