From: Petr Lautrbach <plautrba@redhat.com>
To: SElinux list <selinux@vger.kernel.org>
Cc: William Roberts <bill.c.roberts@gmail.com>
Subject: Re: [PATCH] libselinux: Always close status page fd
Date: Thu, 14 Jan 2021 15:54:26 +0100 [thread overview]
Message-ID: <87a6tba7rx.fsf@redhat.com> (raw)
In-Reply-To: <CAFftDdoUFfoztETJmr2TpLOS-mndbmuvbwHLFjfzhArOT=4FEw@mail.gmail.com>
William Roberts <bill.c.roberts@gmail.com> writes:
> On Thu, Jan 14, 2021 at 7:42 AM Petr Lautrbach <plautrba@redhat.com> 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@redhat.com>
>> ---
>> libselinux/src/sestatus.c | 6 ++----
>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/libselinux/src/sestatus.c b/libselinux/src/sestatus.c
>> index 9ff2785d876a..6a243b7bcdfb 100644
>> --- a/libselinux/src/sestatus.c
>> +++ b/libselinux/src/sestatus.c
>> @@ -298,11 +298,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 */
>> @@ -379,6 +378,7 @@ void selinux_status_close(void)
>> avc_netlink_release_fd();
>> avc_netlink_close();
>> selinux_status = NULL;
>> + close(selinux_status_fd);
>> return;
>> }
I'll drop this one. It's already closed by avc_netlink_close()
>
>> @@ -388,7 +388,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);
I believe this is correct. selinux_stats_fd is not assigned when mmap()
doesn't return MAP_FAILED
>> }
>> --
>> 2.30.0
>>
>
> Nack, the fd in the mmap of the status page and the selinux_status_fd
> (avc mount) are different fd's.
> The selinux_status_fd is for the AVC netlink socket fallback. If you
> drop those hunks I'd take the patch.
next prev parent reply other threads:[~2021-01-14 14:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-14 13:39 [PATCH] libselinux: Always close status page fd Petr Lautrbach
2021-01-14 14:30 ` William Roberts
2021-01-14 14:33 ` William Roberts
2021-01-14 14:46 ` William Roberts
2021-01-14 14:54 ` Petr Lautrbach [this message]
2021-01-14 15:11 ` William Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a6tba7rx.fsf@redhat.com \
--to=plautrba@redhat.com \
--cc=bill.c.roberts@gmail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.