udf: Prevent buffer overrun with multi-byte characters
authorAndrew Gabbasov <andrew_gabbasov@mentor.com>
Thu, 24 Dec 2015 16:25:32 +0000 (10:25 -0600)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 13 Feb 2016 10:34:07 +0000 (10:34 +0000)
commitdba4f816e8204bfc3de568ba386cb72178c55715
tree0d4f60f09aa669b625c838173eda338458e670ed
parent8b0969157ef3d3db0ba4541b5f4ec399f5fddccd
udf: Prevent buffer overrun with multi-byte characters

commit ad402b265ecf6fa22d04043b41444cdfcdf4f52d upstream.

udf_CS0toUTF8 function stops the conversion when the output buffer
length reaches UDF_NAME_LEN-2, which is correct maximum name length,
but, when checking, it leaves the space for a single byte only,
while multi-bytes output characters can take more space, causing
buffer overflow.

Similar error exists in udf_CS0toNLS function, that restricts
the output length to UDF_NAME_LEN, while actual maximum allowed
length is UDF_NAME_LEN-2.

In these cases the output can override not only the current buffer
length field, causing corruption of the name buffer itself, but also
following allocation structures, causing kernel crash.

Adjust the output length checks in both functions to prevent buffer
overruns in case of multi-bytes UTF8 or NLS characters.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/udf/unicode.c