From 9559ac9dd63c7d4ef40b964cbf341612b4d60ab6 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 16 Jun 2021 18:20:25 +0200 Subject: [PATCH] Kernel: Correctly decode proc_file_type from identifier inode identifiers in ProcFS are encoded in a way that the parent ID is shifted 12 bits to the left and the PID is shifted by 16 bits. This means that the rightmost 12 bits are reserved for the file type or the fd. Since the to_fd and to_proc_file_type decoders only decoded the rightmost 8 bits, decoded values would wrap around beyond values of 255, resulting in a different value compared to what was originally encoded. --- Kernel/FileSystem/ProcFS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 76bad8a63a..0bc78c51fe 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -126,13 +126,13 @@ static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier) { - return (ProcFileType)(identifier.index().value() & 0xff); + return (ProcFileType)(identifier.index().value() & 0xfff); } static inline int to_fd(const InodeIdentifier& identifier) { VERIFY(to_proc_parent_directory(identifier) == PDI_PID_fd); - return (identifier.index().value() & 0xff) - FI_MaxStaticFileIndex; + return (identifier.index().value() & 0xfff) - FI_MaxStaticFileIndex; } static inline size_t to_sys_index(const InodeIdentifier& identifier)