# git rev-parse -q --verify 3593030761630e09200072a4bd06468892c27be3^{commit} 3593030761630e09200072a4bd06468892c27be3 already have revision, skipping fetch # git checkout -q -f -B kisskb 3593030761630e09200072a4bd06468892c27be3 # git clean -qxdf # < git log -1 # commit 3593030761630e09200072a4bd06468892c27be3 # Author: Linus Torvalds # Date: Tue Feb 15 15:28:00 2022 -0800 # # tty: n_tty: do not look ahead for EOL character past the end of the buffer # # Daniel Gibson reports that the n_tty code gets line termination wrong in # very specific cases: # # "If you feed a line with exactly 64 chars + terminating newline, and # directly afterwards (without reading) another line into a pseudo # terminal, the the first read() on the other side will return the 64 # char line *without* terminating newline, and the next read() will # return the missing terminating newline AND the complete next line (if # it fits in the buffer)" # # and bisected the behavior to commit 3b830a9c34d5 ("tty: convert # tty_ldisc_ops 'read()' function to take a kernel pointer"). # # Now, digging deeper, it turns out that the behavior isn't exactly new: # what changed in commit 3b830a9c34d5 was that the tty line discipline # .read() function is now passed an intermediate kernel buffer rather than # the final user space buffer. # # And that intermediate kernel buffer is 64 bytes in size - thus that # special case with exactly 64 bytes plus terminating newline. # # The same problem did exist before, but historically the boundary was not # the 64-byte chunk, but the user-supplied buffer size, which is obviously # generally bigger (and potentially bigger than N_TTY_BUF_SIZE, which # would hide the issue entirely). # # The reason is that the n_tty canon_copy_from_read_buf() code would look # ahead for the EOL character one byte further than it would actually # copy. It would then decide that it had found the terminator, and unmark # it as an EOL character - which in turn explains why the next read # wouldn't then be terminated by it. # # Now, the reason it did all this in the first place is related to some # historical and pretty obscure EOF behavior, see commit ac8f3bf8832a # ("n_tty: Fix poll() after buffer-limited eof push read") and commit # 40d5e0905a03 ("n_tty: Fix EOF push handling"). # # And the reason for the EOL confusion is that we treat EOF as a special # EOL condition, with the EOL character being NUL (aka "__DISABLED_CHAR" # in the kernel sources). # # So that EOF look-ahead also affects the normal EOL handling. # # This patch just removes the look-ahead that causes problems, because EOL # is much more critical than the historical "EOF in the middle of a line # that coincides with the end of the buffer" handling ever was. # # Now, it is possible that we should indeed re-introduce the "look at next # character to see if it's a EOF" behavior, but if so, that should be done # not at the kernel buffer chunk boundary in canon_copy_from_read_buf(), # but at a higher level, when we run out of the user buffer. # # In particular, the place to do that would be at the top of # 'n_tty_read()', where we check if it's a continuation of a previously # started read, and there is no more buffer space left, we could decide to # just eat the __DISABLED_CHAR at that point. # # But that would be a separate patch, because I suspect nobody actually # cares, and I'd like to get a report about it before bothering. # # Fixes: 3b830a9c34d5 ("tty: convert tty_ldisc_ops 'read()' function to take a kernel pointer") # Fixes: ac8f3bf8832a ("n_tty: Fix poll() after buffer-limited eof push read") # Fixes: 40d5e0905a03 ("n_tty: Fix EOF push handling") # Link: https://bugzilla.kernel.org/show_bug.cgi?id=215611 # Reported-and-tested-by: Daniel Gibson # Cc: Peter Hurley # Cc: Greg Kroah-Hartman # Cc: Jiri Slaby # Signed-off-by: Linus Torvalds # < /opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux-gcc --version # < /opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux-ld --version # < git log --format=%s --max-count=1 3593030761630e09200072a4bd06468892c27be3 # < make -s -j 32 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64 CROSS_COMPILE=/opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux- SUBARCH=x86_64 allmodconfig # Added to kconfig CONFIG_STANDALONE=y # Added to kconfig CONFIG_KCOV=n # Added to kconfig CONFIG_GCC_PLUGINS=n # Added to kconfig CONFIG_GCC_PLUGIN_CYC_COMPLEXITY=n # Added to kconfig CONFIG_GCC_PLUGIN_SANCOV=n # Added to kconfig CONFIG_GCC_PLUGIN_LATENT_ENTROPY=n # Added to kconfig CONFIG_GCC_PLUGIN_STRUCTLEAK=n # Added to kconfig CONFIG_GCC_PLUGIN_RANDSTRUCT=n # Added to kconfig CONFIG_UML_NET=n # Added to kconfig CONFIG_UML_NET_ETHERTAP=n # Added to kconfig CONFIG_UML_NET_TUNTAP=n # Added to kconfig CONFIG_UML_NET_SLIP=n # Added to kconfig CONFIG_UML_NET_DAEMON=n # Added to kconfig CONFIG_UML_NET_VDE=n # Added to kconfig CONFIG_UML_NET_MCAST=n # Added to kconfig CONFIG_UML_NET_PCAP=n # Added to kconfig CONFIG_UML_NET_SLIRP=n # Added to kconfig CONFIG_GCOV_KERNEL=n # Added to kconfig CONFIG_DEBUG_INFO_BTF=n # Added to kconfig CONFIG_BPF_PRELOAD=n # < make -s -j 32 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64 CROSS_COMPILE=/opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux- SUBARCH=x86_64 help # make -s -j 32 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64 CROSS_COMPILE=/opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux- SUBARCH=x86_64 olddefconfig .config:12008:warning: override: reassigning to symbol GCC_PLUGIN_SANCOV .config:12011:warning: override: reassigning to symbol GCC_PLUGIN_RANDSTRUCT .config:12013:warning: override: reassigning to symbol UML_NET_ETHERTAP .config:12015:warning: override: reassigning to symbol UML_NET_SLIP .config:12018:warning: override: reassigning to symbol UML_NET_MCAST .config:12020:warning: override: reassigning to symbol UML_NET_SLIRP # make -s -j 32 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64 CROSS_COMPILE=/opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux- SUBARCH=x86_64 In file included from /kisskb/src/arch/x86/um/asm/processor.h:41:0, from /kisskb/src/include/linux/mutex.h:19, from /kisskb/src/include/linux/kernfs.h:11, from /kisskb/src/include/linux/sysfs.h:16, from /kisskb/src/include/linux/kobject.h:20, from /kisskb/src/include/linux/pci.h:35, from /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:25: /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c: In function 'kfd_cpumask_to_apic_id': /kisskb/src/arch/um/include/asm/processor-generic.h:103:18: error: called object is not a function or function pointer #define cpu_data (&boot_cpu_data) ^ /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1556:9: note: in expansion of macro 'cpu_data' return cpu_data(first_cpu_of_numa_node).apicid; ^ /kisskb/src/drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.c:1560:1: error: control reaches end of non-void function [-Werror=return-type] } ^ cc1: all warnings being treated as errors make[5]: *** [/kisskb/src/scripts/Makefile.build:288: drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_topology.o] Error 1 make[4]: *** [/kisskb/src/scripts/Makefile.build:550: drivers/gpu/drm/amd/amdgpu] Error 2 make[4]: *** Waiting for unfinished jobs.... /kisskb/src/drivers/vfio/pci/vfio_pci_rdwr.c: In function 'vfio_pci_vga_rw': /kisskb/src/drivers/vfio/pci/vfio_pci_rdwr.c:317:11: error: implicit declaration of function 'ioport_map' [-Werror=implicit-function-declaration] iomem = ioport_map(0x3b0, 0x3bb - 0x3b0 + 1); ^ /kisskb/src/drivers/vfio/pci/vfio_pci_rdwr.c:317:9: error: assignment makes pointer from integer without a cast [-Werror=int-conversion] iomem = ioport_map(0x3b0, 0x3bb - 0x3b0 + 1); ^ /kisskb/src/drivers/vfio/pci/vfio_pci_rdwr.c:324:9: error: assignment makes pointer from integer without a cast [-Werror=int-conversion] iomem = ioport_map(0x3c0, 0x3df - 0x3c0 + 1); ^ /kisskb/src/drivers/vfio/pci/vfio_pci_rdwr.c:338:15: error: implicit declaration of function 'ioport_unmap' [-Werror=implicit-function-declaration] is_ioport ? ioport_unmap(iomem) : iounmap(iomem); ^ cc1: all warnings being treated as errors make[4]: *** [/kisskb/src/scripts/Makefile.build:288: drivers/vfio/pci/vfio_pci_rdwr.o] Error 1 make[3]: *** [/kisskb/src/scripts/Makefile.build:550: drivers/vfio/pci] Error 2 make[2]: *** [/kisskb/src/scripts/Makefile.build:550: drivers/vfio] Error 2 make[2]: *** Waiting for unfinished jobs.... make[3]: *** [/kisskb/src/scripts/Makefile.build:550: drivers/gpu/drm] Error 2 make[2]: *** [/kisskb/src/scripts/Makefile.build:550: drivers/gpu] Error 2 make[1]: *** [/kisskb/src/Makefile:1831: drivers] Error 2 make: *** [Makefile:219: __sub-make] Error 2 Command 'make -s -j 32 ARCH=um O=/kisskb/build/linus_um-allmodconfig_um-x86_64 CROSS_COMPILE=/opt/cross/kisskb/fe-x86-64-core-i7-2017.05/bin/x86_64-linux- SUBARCH=x86_64 ' returned non-zero exit status 2 # rm -rf /kisskb/build/linus_um-allmodconfig_um-x86_64 # Build took: 0:15:03.630811