|
|
d8307d |
commit 21cc130b78a4db9113fb6695e2b951e697662440
|
|
|
d8307d |
Author: Dmitry V. Levin <ldv@altlinux.org>
|
|
|
d8307d |
Date: Wed Feb 13 01:20:51 2019 +0000
|
|
|
d8307d |
|
|
|
d8307d |
libio: do not attempt to free wide buffers of legacy streams [BZ #24228]
|
|
|
d8307d |
|
|
|
d8307d |
Commit a601b74d31ca086de38441d316a3dee24c866305 aka glibc-2.23~693
|
|
|
d8307d |
("In preparation for fixing BZ#16734, fix failure in misc/tst-error1-mem
|
|
|
d8307d |
when _G_HAVE_MMAP is turned off.") introduced a regression:
|
|
|
d8307d |
_IO_unbuffer_all now invokes _IO_wsetb to free wide buffers of all
|
|
|
d8307d |
files, including legacy standard files which are small statically
|
|
|
d8307d |
allocated objects that do not have wide buffers and the _mode member,
|
|
|
d8307d |
causing memory corruption.
|
|
|
d8307d |
|
|
|
d8307d |
Another memory corruption in _IO_unbuffer_all happens when -1
|
|
|
d8307d |
is assigned to the _mode member of legacy standard files that
|
|
|
d8307d |
do not have it.
|
|
|
d8307d |
|
|
|
d8307d |
[BZ #24228]
|
|
|
d8307d |
* libio/genops.c (_IO_unbuffer_all)
|
|
|
d8307d |
[SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)]: Do not attempt to free wide
|
|
|
d8307d |
buffers and access _IO_FILE_complete members of legacy libio streams.
|
|
|
d8307d |
* libio/tst-bz24228.c: New file.
|
|
|
d8307d |
* libio/tst-bz24228.map: Likewise.
|
|
|
d8307d |
* libio/Makefile [build-shared] (tests): Add tst-bz24228.
|
|
|
d8307d |
[build-shared] (generated): Add tst-bz24228.mtrace and
|
|
|
d8307d |
tst-bz24228.check.
|
|
|
d8307d |
[run-built-tests && build-shared] (tests-special): Add
|
|
|
d8307d |
$(objpfx)tst-bz24228-mem.out.
|
|
|
d8307d |
(LDFLAGS-tst-bz24228, tst-bz24228-ENV): New variables.
|
|
|
d8307d |
($(objpfx)tst-bz24228-mem.out): New rule.
|
|
|
d8307d |
|
|
|
d8307d |
# Conflicts:
|
|
|
d8307d |
# libio/Makefile
|
|
|
d8307d |
|
|
|
d8307d |
diff --git a/libio/Makefile b/libio/Makefile
|
|
|
d8307d |
index cbfaf3832a45fc22..314e03d5ce72be2d 100644
|
|
|
d8307d |
--- a/libio/Makefile
|
|
|
d8307d |
+++ b/libio/Makefile
|
|
|
d8307d |
@@ -73,6 +73,9 @@ ifeq (yes,$(build-shared))
|
|
|
d8307d |
# Add test-fopenloc only if shared library is enabled since it depends on
|
|
|
d8307d |
# shared localedata objects.
|
|
|
d8307d |
tests += tst-fopenloc
|
|
|
d8307d |
+# Add tst-bz24228 only if shared library is enabled since it can never meet its
|
|
|
d8307d |
+# objective with static linking because the relevant code just is not there.
|
|
|
d8307d |
+tests += tst-bz24228
|
|
|
d8307d |
endif
|
|
|
d8307d |
test-srcs = test-freopen
|
|
|
d8307d |
|
|
|
d8307d |
@@ -153,11 +156,14 @@ CFLAGS-oldtmpfile.c += -fexceptions
|
|
|
d8307d |
|
|
|
d8307d |
CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
|
|
|
d8307d |
|
|
|
d8307d |
+LDFLAGS-tst-bz24228 = -Wl,--version-script=tst-bz24228.map
|
|
|
d8307d |
+
|
|
|
d8307d |
tst_wprintf2-ARGS = "Some Text"
|
|
|
d8307d |
|
|
|
d8307d |
test-fmemopen-ENV = MALLOC_TRACE=$(objpfx)test-fmemopen.mtrace
|
|
|
d8307d |
tst-fopenloc-ENV = MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
|
|
|
d8307d |
tst-bz22415-ENV = MALLOC_TRACE=$(objpfx)tst-bz22415.mtrace
|
|
|
d8307d |
+tst-bz24228-ENV = MALLOC_TRACE=$(objpfx)tst-bz24228.mtrace
|
|
|
d8307d |
|
|
|
d8307d |
generated += test-fmemopen.mtrace test-fmemopen.check
|
|
|
d8307d |
generated += tst-fopenloc.mtrace tst-fopenloc.check
|
|
|
d8307d |
@@ -166,6 +172,7 @@ generated += tst-bz22415.mtrace tst-bz22415.check
|
|
|
d8307d |
aux := fileops genops stdfiles stdio strops
|
|
|
d8307d |
|
|
|
d8307d |
ifeq ($(build-shared),yes)
|
|
|
d8307d |
+generated += tst-bz24228.mtrace tst-bz24228.check
|
|
|
d8307d |
aux += oldfileops oldstdfiles
|
|
|
d8307d |
endif
|
|
|
d8307d |
|
|
|
d8307d |
@@ -180,7 +187,8 @@ tests-special += $(objpfx)test-freopen.out $(objpfx)test-fmemopen-mem.out \
|
|
|
d8307d |
ifeq (yes,$(build-shared))
|
|
|
d8307d |
# Run tst-fopenloc-cmp.out and tst-openloc-mem.out only if shared
|
|
|
d8307d |
# library is enabled since they depend on tst-fopenloc.out.
|
|
|
d8307d |
-tests-special += $(objpfx)tst-fopenloc-cmp.out $(objpfx)tst-fopenloc-mem.out
|
|
|
d8307d |
+tests-special += $(objpfx)tst-fopenloc-cmp.out $(objpfx)tst-fopenloc-mem.out \
|
|
|
d8307d |
+ $(objpfx)tst-bz24228-mem.out
|
|
|
d8307d |
endif
|
|
|
d8307d |
endif
|
|
|
d8307d |
|
|
|
d8307d |
@@ -232,3 +240,7 @@ $(objpfx)tst-fopenloc-mem.out: $(objpfx)tst-fopenloc.out
|
|
|
d8307d |
$(objpfx)tst-bz22415-mem.out: $(objpfx)tst-bz22415.out
|
|
|
d8307d |
$(common-objpfx)malloc/mtrace $(objpfx)tst-bz22415.mtrace > $@; \
|
|
|
d8307d |
$(evaluate-test)
|
|
|
d8307d |
+
|
|
|
d8307d |
+$(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
|
|
|
d8307d |
+ $(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
|
|
|
d8307d |
+ $(evaluate-test)
|
|
|
d8307d |
diff --git a/libio/genops.c b/libio/genops.c
|
|
|
d8307d |
index 2fec221b99729718..a8241dd26640bbcb 100644
|
|
|
d8307d |
--- a/libio/genops.c
|
|
|
d8307d |
+++ b/libio/genops.c
|
|
|
d8307d |
@@ -789,9 +789,16 @@ _IO_unbuffer_all (void)
|
|
|
d8307d |
|
|
|
d8307d |
for (fp = (FILE *) _IO_list_all; fp; fp = fp->_chain)
|
|
|
d8307d |
{
|
|
|
d8307d |
+ int legacy = 0;
|
|
|
d8307d |
+
|
|
|
d8307d |
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
|
|
|
d8307d |
+ if (__glibc_unlikely (_IO_vtable_offset (fp) != 0))
|
|
|
d8307d |
+ legacy = 1;
|
|
|
d8307d |
+#endif
|
|
|
d8307d |
+
|
|
|
d8307d |
if (! (fp->_flags & _IO_UNBUFFERED)
|
|
|
d8307d |
/* Iff stream is un-orientated, it wasn't used. */
|
|
|
d8307d |
- && fp->_mode != 0)
|
|
|
d8307d |
+ && (legacy || fp->_mode != 0))
|
|
|
d8307d |
{
|
|
|
d8307d |
#ifdef _IO_MTSAFE_IO
|
|
|
d8307d |
int cnt;
|
|
|
d8307d |
@@ -805,7 +812,7 @@ _IO_unbuffer_all (void)
|
|
|
d8307d |
__sched_yield ();
|
|
|
d8307d |
#endif
|
|
|
d8307d |
|
|
|
d8307d |
- if (! dealloc_buffers && !(fp->_flags & _IO_USER_BUF))
|
|
|
d8307d |
+ if (! legacy && ! dealloc_buffers && !(fp->_flags & _IO_USER_BUF))
|
|
|
d8307d |
{
|
|
|
d8307d |
fp->_flags |= _IO_USER_BUF;
|
|
|
d8307d |
|
|
|
d8307d |
@@ -816,7 +823,7 @@ _IO_unbuffer_all (void)
|
|
|
d8307d |
|
|
|
d8307d |
_IO_SETBUF (fp, NULL, 0);
|
|
|
d8307d |
|
|
|
d8307d |
- if (fp->_mode > 0)
|
|
|
d8307d |
+ if (! legacy && fp->_mode > 0)
|
|
|
d8307d |
_IO_wsetb (fp, NULL, NULL, 0);
|
|
|
d8307d |
|
|
|
d8307d |
#ifdef _IO_MTSAFE_IO
|
|
|
d8307d |
@@ -827,7 +834,8 @@ _IO_unbuffer_all (void)
|
|
|
d8307d |
|
|
|
d8307d |
/* Make sure that never again the wide char functions can be
|
|
|
d8307d |
used. */
|
|
|
d8307d |
- fp->_mode = -1;
|
|
|
d8307d |
+ if (! legacy)
|
|
|
d8307d |
+ fp->_mode = -1;
|
|
|
d8307d |
}
|
|
|
d8307d |
|
|
|
d8307d |
#ifdef _IO_MTSAFE_IO
|
|
|
d8307d |
diff --git a/libio/tst-bz24228.c b/libio/tst-bz24228.c
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..6a74500d473ceeab
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/libio/tst-bz24228.c
|
|
|
d8307d |
@@ -0,0 +1,29 @@
|
|
|
d8307d |
+/* BZ #24228 check for memory corruption in legacy libio
|
|
|
d8307d |
+ Copyright (C) 2019 Free Software Foundation, Inc.
|
|
|
d8307d |
+ This file is part of the GNU C Library.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
d8307d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
d8307d |
+ License as published by the Free Software Foundation; either
|
|
|
d8307d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
d8307d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d8307d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
d8307d |
+ Lesser General Public License for more details.
|
|
|
d8307d |
+
|
|
|
d8307d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
d8307d |
+ License along with the GNU C Library; if not, see
|
|
|
d8307d |
+ <https://www.gnu.org/licenses/>. */
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <mcheck.h>
|
|
|
d8307d |
+#include <support/test-driver.h>
|
|
|
d8307d |
+
|
|
|
d8307d |
+static int
|
|
|
d8307d |
+do_test (void)
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ mtrace ();
|
|
|
d8307d |
+ return 0;
|
|
|
d8307d |
+}
|
|
|
d8307d |
+
|
|
|
d8307d |
+#include <support/test-driver.c>
|
|
|
d8307d |
diff --git a/libio/tst-bz24228.map b/libio/tst-bz24228.map
|
|
|
d8307d |
new file mode 100644
|
|
|
d8307d |
index 0000000000000000..4383e0817d7f5583
|
|
|
d8307d |
--- /dev/null
|
|
|
d8307d |
+++ b/libio/tst-bz24228.map
|
|
|
d8307d |
@@ -0,0 +1,5 @@
|
|
|
d8307d |
+# Hide the symbol from libc.so.6 to switch to the libio/oldfileops.c
|
|
|
d8307d |
+# implementation when it is available for the architecture.
|
|
|
d8307d |
+{
|
|
|
d8307d |
+ local: _IO_stdin_used;
|
|
|
d8307d |
+};
|