Re: [PATCH v2] libselinux: Always close status page fd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 14, 2021 at 10:02 AM Petr Lautrbach <plautrba@xxxxxxxxxx> wrote:
>
> According to mmap(2) after the mmap() call has returned, the file
> descriptor, fd, can be closed immediately without invalidating the
> mapping.
>
> Signed-off-by: Petr Lautrbach <plautrba@xxxxxxxxxx>
> ---
>
> Changes against v1:
> - selinux_status_fd is completely droped as it's actually unused
>
>  libselinux/src/sestatus.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/libselinux/src/sestatus.c b/libselinux/src/sestatus.c
> index 9ff2785d876a..12b015e088ea 100644
> --- a/libselinux/src/sestatus.c
> +++ b/libselinux/src/sestatus.c
> @@ -37,7 +37,6 @@ struct selinux_status_t
>   * Valid Pointer : opened and mapped correctly
>   */
>  static struct selinux_status_t *selinux_status = NULL;
> -static int                     selinux_status_fd;
>  static uint32_t                        last_seqno;
>  static uint32_t                        last_policyload;
>
> @@ -298,11 +297,10 @@ int selinux_status_open(int fallback)
>                 goto error;
>
>         selinux_status = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
> +       close(fd);
>         if (selinux_status == MAP_FAILED) {
> -               close(fd);
>                 goto error;
>         }
> -       selinux_status_fd = fd;
>         last_seqno = (uint32_t)(-1);
>
>         /* sequence must not be changed during references */
> @@ -336,7 +334,6 @@ error:
>
>                 /* mark as fallback mode */
>                 selinux_status = MAP_FAILED;
> -               selinux_status_fd = avc_netlink_acquire_fd();
>                 last_seqno = (uint32_t)(-1);
>
>                 if (avc_using_threads)
> @@ -388,7 +385,5 @@ void selinux_status_close(void)
>                 munmap(selinux_status, pagesize);
>         selinux_status = NULL;
>
> -       close(selinux_status_fd);
> -       selinux_status_fd = -1;
>         last_seqno = (uint32_t)(-1);
>  }
> --
> 2.30.0
>

ack and staged. I love a negative diffstat. Thanks Petr.
https://github.com/SELinuxProject/selinux/pull/279




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux