pam_namespace: protect_dir(): use O_DIRECTORY to prevent local DoS situations
(backporting, CVE-2024-22356)
Without O_DIRECTORY the path crawling logic is subject to e.g. FIFOs
being placed in user controlled directories, causing the PAM module to
block indefinitely during `openat()`.
Pass O_DIRECTORY to cause the `openat()` to fail if the path does not
refer to a directory.
With this the check whether the final path element is a directory
becomes unnecessary, drop it.
Original: upstream, https://github.com/linux-pam/linux-pam/commit/031bb5a
Change-Id: I099e6d7fa62446160babf79d41fb19bfbfe5b186
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
(cherry picked from commit
cb1ff0632d1d392606509c46d8fd25271a715825)