[PATCH v2 2/2] hostfs: store permissions in extended attributes

Marko Petrović petrovicmarko2006 at gmail.com
Fri Apr 14 10:52:30 PDT 2023


On Fri Apr 14, 2023 at 12:54 PM CEST, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
> > Von: "Marko Petrović" <petrovicmarko2006 at gmail.com>
> > +static int uml_chown(const char *pathname, unsigned int owner, unsigned int
> > group)
>
> Is there a specific reason why you are not using uid_t and gid_t?
>
> > +{
> > +	int status;
> > +
> > +	if (use_xattr) {
> > +		if (owner != -1) {
>
> Doesn't -1 clash with the uid space?
> Same for gid.
>
> > +			status = setxattr(pathname, "user.umluid", &owner,
> > +							sizeof(unsigned int), 0);
>
>
> I'd prefer storing the values platform independent. e.g. in __le32. 
> Just to be future prove.
>
> Thanks,
> //richard
Hello,
Thank you for your feedback!

There is no specific reason for preferring one over the other between
uid_t/gid_t and unsigned int. I will change those types back to uid_t
and gid_t.

About using -1 for uid and gid, in documentation for chown it is stated
that -1 shall be used if the desired value should not be changed, since
normally chown(2) accepts both uid and gid for changing in one system
call.
In the concrete implementation, since the underlying type is unsigned
int, the -1 will be written in 2's complement and then treated as an
unsigned positive number. For the size of 4 bytes for unsigned int, the
resulting number is 4294967295. That is also the maximum possible number
of users on Linux, but Linux user IDs go from 0 to 4294967294 so that
last one is outside UID space and reserved as "don't change" flag for
chown(2).

In regard to the store of values in platform independent way, in my
humble opinion, Johannes' recommendation may be preferred (storing all
permissions in one string) because besides this it also solves the
problem of one setxattr() succeding and other failing (for whatever
reason may that happen) in uml_chown().

Best regards,
Marko Petrović



More information about the linux-um mailing list