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.
This commit is contained in:
Tim Schumacher 2021-06-16 18:20:25 +02:00 committed by Andreas Kling
parent 8cd96f031d
commit 9559ac9dd6

View file

@ -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)