From: Gao Xiang <xiang@kernel.org> To: linux-erofs@lists.ozlabs.org, LKML <linux-kernel@vger.kernel.org> Cc: Lasse Collin <lasse.collin@tukaani.org>, Chao Yu <chao@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Greg KH <gregkh@linuxfoundation.org>, Linus Torvalds <torvalds@linux-foundation.org>, Gao Xiang <hsiangkao@linux.alibaba.com> Subject: [PATCH 2/7] lib/xz: Validate the value before assigning it to an enum variable Date: Mon, 11 Oct 2021 05:31:40 +0800 [thread overview] Message-ID: <20211010213145.17462-3-xiang@kernel.org> (raw) In-Reply-To: <20211010213145.17462-1-xiang@kernel.org> From: Lasse Collin <lasse.collin@tukaani.org> 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. Signed-off-by: Lasse Collin <lasse.collin@tukaani.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> --- lib/xz/xz_dec_stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/xz/xz_dec_stream.c b/lib/xz/xz_dec_stream.c index fea86deaaa01..683570b93a8c 100644 --- a/lib/xz/xz_dec_stream.c +++ b/lib/xz/xz_dec_stream.c @@ -402,12 +402,12 @@ static enum xz_ret dec_stream_header(struct xz_dec *s) * 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 -- 2.20.1
WARNING: multiple messages have this Message-ID (diff)
From: Gao Xiang <xiang@kernel.org> To: linux-erofs@lists.ozlabs.org, LKML <linux-kernel@vger.kernel.org> Cc: Lasse Collin <lasse.collin@tukaani.org>, Greg KH <gregkh@linuxfoundation.org>, Gao Xiang <hsiangkao@linux.alibaba.com>, Andrew Morton <akpm@linux-foundation.org>, Linus Torvalds <torvalds@linux-foundation.org> Subject: [PATCH 2/7] lib/xz: Validate the value before assigning it to an enum variable Date: Mon, 11 Oct 2021 05:31:40 +0800 [thread overview] Message-ID: <20211010213145.17462-3-xiang@kernel.org> (raw) In-Reply-To: <20211010213145.17462-1-xiang@kernel.org> From: Lasse Collin <lasse.collin@tukaani.org> 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. Signed-off-by: Lasse Collin <lasse.collin@tukaani.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> --- lib/xz/xz_dec_stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/xz/xz_dec_stream.c b/lib/xz/xz_dec_stream.c index fea86deaaa01..683570b93a8c 100644 --- a/lib/xz/xz_dec_stream.c +++ b/lib/xz/xz_dec_stream.c @@ -402,12 +402,12 @@ static enum xz_ret dec_stream_header(struct xz_dec *s) * 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 -- 2.20.1
next prev parent reply other threads:[~2021-10-10 21:32 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-10 21:31 [PATCH 0/7] erofs: add LZMA compression support Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-10 21:31 ` [PATCH 1/7] lib/xz: Avoid overlapping memcpy() with invalid input with in-place decompression Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-10 21:31 ` Gao Xiang [this message] 2021-10-10 21:31 ` [PATCH 2/7] lib/xz: Validate the value before assigning it to an enum variable Gao Xiang 2021-10-10 21:31 ` [PATCH 3/7] lib/xz: Move s->lzma.len = 0 initialization to lzma_reset() Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-10 21:31 ` [PATCH 4/7] lib/xz: Add MicroLZMA decoder Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-10 21:31 ` [PATCH 5/7] lib/xz, lib/decompress_unxz.c: Fix spelling in comments Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-10 21:31 ` [PATCH 6/7] erofs: rename some generic methods in decompressor Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-19 13:03 ` Chao Yu 2021-10-19 13:03 ` Chao Yu 2021-10-10 21:31 ` [PATCH 7/7] erofs: lzma compression support Gao Xiang 2021-10-10 21:31 ` Gao Xiang 2021-10-19 13:04 ` Chao Yu 2021-10-19 13:04 ` Chao Yu 2021-10-14 1:45 ` [PATCH 0/7] erofs: add LZMA " Gao Xiang 2021-10-14 1:45 ` Gao Xiang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211010213145.17462-3-xiang@kernel.org \ --to=xiang@kernel.org \ --cc=akpm@linux-foundation.org \ --cc=chao@kernel.org \ --cc=gregkh@linuxfoundation.org \ --cc=hsiangkao@linux.alibaba.com \ --cc=lasse.collin@tukaani.org \ --cc=linux-erofs@lists.ozlabs.org \ --cc=linux-kernel@vger.kernel.org \ --cc=torvalds@linux-foundation.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.