Re: [PATCH 1/3] tools/mount-flatpak: init

Alyssa Ross
2025-11-15T12:01:55Z

[-- Attachment #1: Type: text/plain, Size: 2307 bytes --]

Alyssa Ross <hi@alyssa.is> writes:

> Demi Marie Obenour <demiobenour@gmail.com> writes:
>
>> On 11/14/25 06:12, Alyssa Ross wrote:
>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>
>>>> On 11/13/25 07:04, Alyssa Ross wrote:
>>>>> diff --git a/tools/mount-flatpak/mount-flatpak.c b/tools/mount-flatpak/mount-flatpak.c
>>>>> new file mode 100644
>>>>> index 0000000..8e09d1d
>>>>> --- /dev/null
>>>>> +++ b/tools/mount-flatpak/mount-flatpak.c
>>>>> @@ -0,0 +1,294 @@
>>>>> +// SPDX-License-Identifier: EUPL-1.2+
>>>>> +// SPDX-FileCopyrightText: 2025 Alyssa Ross <hi@alyssa.is>
>>>>> +
>>>>> +#include "config.h"
>>>>> +#include "metadata.h"
>>>>> +
>>>>> +#include <err.h>
>>>>> +#include <fcntl.h>
>>>>> +#include <stdlib.h>
>>>>> +#include <stdio.h>
>>>>> +#include <string.h>
>>>>> +#include <unistd.h>
>>>>> +
>>>>> +#include <sys/stat.h>
>>>>> +#include <sys/syscall.h>
>>>>> +
>>>>> +#include <linux/mount.h>
>>>>> +#include <linux/openat2.h>
>>>>> +
>>>>> +static void bind_mount(int source_fd, const char *source,
>>>>> + int target_fd, const char *target)
>>>>> +{
>>>>> + int source_tree = syscall(SYS_open_tree, source_fd, source,
>>>>> + AT_EMPTY_PATH | OPEN_TREE_CLOEXEC |
>>>>> + OPEN_TREE_CLONE | AT_RECURSIVE);
>>>>> + if (source_tree == -1)
>>>>> + err(EXIT_FAILURE, "open_tree %s", source);
>>>>> + if (syscall(SYS_move_mount, source_tree, "", target_fd, target,
>>>>> + MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH) == -1)
>>>>> + err(EXIT_FAILURE, "move_mount");
>>>>
>>>> Missing checks that target does not contain "/" and is not "." or "..".
>>>
>>> Right, yes, move_mount doesn't have RESOLVE_BENEATH semantics. Ideally
>>> I suppose we can leave target empty and only use an fd, but I don't
>>> think that works in all circumstances.
>>
>> Which ones does it fail in? Also, should this set the mount read-only?
>
> I had it that way originally, but I decided to replace it with one
> read-only self-bind-mount at the end because making just these read-only
> and not the parent directories felt a bit ad-hoc.

Oh and as for where it fails, I wasn't able to remount a directory over
itself using empty paths for both.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]