Live data from Hacker News

How do groups work on Linux?

jvns.ca

41–50 of 68 posts

Re: How do groups work on Linux?

#41
post #40

Earlier quoted context omitted.

$ mkdir file.txt $ ls -l drwxr-xr-x 2 USER GROUP 4096 Nov 21 11:49 file.txt $ chmod -xw file.txt $ for i in {1..180}; do touch file.txt/long_name_$i; done $ ls -l dr--r--r-- 2 USER GROUP 12288 Nov 21 11:50 file.txt File size is a bit off, but that's based on sector size and may be separately configurable - that's a bit beyond my knowledge.

but she says right above it: "So, for example, if a process is owned by the julia user and julia is in the awesome group, then the process would be allowed to read this file."

I'm not sure what you aren't understanding. Directories are just a type of file, so that's not wrong, the dir/file is owned by the `awesome` group, and the group permissions are `r--` so the group can indeed read it.

Re: How do groups work on Linux?

#42
post #34
post #24

Earlier quoted context omitted.

I've seen interviewers ask for the sticky bit and the difference between hard and soft links as similar shibboleths.

I've seen them ask how to restore execution permissions after `chmod a-x /bin/chmod'. I usually answer to those smartasses that I my favourite way is to run the very non-executable /bin/chmod without any file juggling. I'm yet to meet anybody who wasn't surprised that it's possible.

explain?

Re: How do groups work on Linux?

#43
post #30
post #22

Earlier quoted context omitted.

You said, and I quote, "it's Linux-specific" and I was demonstrating that it's not Linux-specific. I also question your point that it's "OS-specific" because I'm pretty sure I had to handle the permission logic myself in the hobby file systems I've written (albeit they were compiled against FUSE rather than kernel objects). However I don't have any examples to hand which I can provide to that end. Hopefully a more ex…

> You said, and I quote, "it's Linux-specific" and I was demonstrating that it's not Linux-specific. You were attempting at demonstrating that the OS specific behaviour can also be exhibited elsewhere (also, you failed at that attempt; you haven't shown what group your shell belongs to). If you were to demonstrate that it's universal (as opposed to be OS specific), you would need to invoke some standard that describe…

> If you were to demonstrate that it's universal

I really wasn't. I was just making a point that it's not just Linux-specific like you claimed. In fact if you re-read the thread you'd realise that nobody argued this behaviour was universal. Given the breadth of POSIX-like systems out there, I doubt anyone would dare make such a bold statement. So you're arguing against point that was never raised.

> And by the way, filesystems are typically implemented in kernel, so saying that it's not kernel that handles them is somewhat misguided.

Well yes file systems generally are, except when they are not. For example ntfs-3g (which is also compiled against FUSE). Plus the file system code is modular - not in the monolithic vs microkernel sense but rather in terms of the body of code is a self-contained chunk that can be optionally compiled in or not. This also means that some file systems are written with some degree of portability in mind (easier said than done I know!!!)

What the argument is about is whether the permission logic described (specifically the setgid bit on folders) is handled by the file system code or externally to the file system code in other parts of the kernel (thus the behavior is defined by the OS rather than the file system).

You're making the case that the behavior is independent to the file system implementation (thus the logic is handled outside the file system code) because it is OS-specific. I'm stating that when I've been writing file systems I've had to handle that logic inside the file system code itself thus the logic is not OS-specific but rather file system-specific.

Now there will be standard way of implementing the logic because people will have certain expectations about how the file system should behave. Much like most $SHELL's broadly follow a common POSIX standard. So you would get the illusion of the discussed behavior being OS-specific even though the actual business logic is implemented at a different stage in the stack (ie the file system code). There might also be instances where one OS might patch the file system code to change its behavior to match the expectations of that OS - but I'm just speculating here. All I know is that I've had to write the logic myself - the kernel did not handle that for me.

I'm obviously not boasting to be a low level kernel hacker so I'd happily bow to a more reasoned argument but the examples you've given have just been guesswork about kernel operations based on some flawed experimentation with user space tools (I say 'flawed' because you didn't even bother to set the setgid bit in your original example when you suggested FreeBSD didn't support said behavior).

> Hint: what's the ownership of a file created on FAT mounted under Linux? It should suggest you what part of the kernel needs to handle the permissions.

That doesn't prove either of our points. Nor anything aside that Linux can mount FAT file systems.

Re: How do groups work on Linux?

#44
post #40

Earlier quoted context omitted.

but she says right above it: "So, for example, if a process is owned by the julia user and julia is in the awesome group, then the process would be allowed to read this file."

I'm not sure what you aren't understanding. Directories are just a type of file, so that's not wrong, the dir/file is owned by the `awesome` group, and the group permissions are `r--` so the group can indeed read it.

Or one could apply Occam's razor and admit that "d" was a typo.

Re: How do groups work on Linux?

#45
post #42
post #34

Earlier quoted context omitted.

I've seen them ask how to restore execution permissions after `chmod a-x /bin/chmod'. I usually answer to those smartasses that I my favourite way is to run the very non-executable /bin/chmod without any file juggling. I'm yet to meet anybody who wasn't surprised that it's possible.

explain?

Manually call e.g. /lib/ld-linux.so.2 (man ld.so for more info).

Re: How do groups work on Linux?

#46
post #12

Ohh, so THAT's why I have to log out and back in to have my group changes take effect. That, along with having to start a new shell to pick up new env vars from ~/.profile, are my two biggest annoyances with the Linux process model. Reminds me a bit of the Windows 98 days when you had to restart to change your IP address. I really wish someone would sit down and figure out how to propagate group and environment chang…

For what it's worth, you have to logout/login on Windows for group changes to take effect. This makes me suspect something similar is at play in the Windows world.

Re: How do groups work on Linux?

#47
post #42
post #34

Earlier quoted context omitted.

I've seen them ask how to restore execution permissions after `chmod a-x /bin/chmod'. I usually answer to those smartasses that I my favourite way is to run the very non-executable /bin/chmod without any file juggling. I'm yet to meet anybody who wasn't surprised that it's possible.

explain?

    shabble@host:~$ cp /bin/chmod /tmp/chmoo
    shabble@host:~$ chmod 600 /tmp/chmoo
    shabble@host:~$ ll /tmp/ch*
    -rw------- 1 shabble shabble 59K Nov 21 17:15 /tmp/chmoo
    shabble@host:~$ /tmp/chmoo
    -bash: /tmp/chmoo: Permission denied
    shabble@host:~$ /lib64/ld-linux-x86-64.so.2 /tmp/chmoo
    /tmp/chmoo: missing operand
    Try '/tmp/chmoo --help' for more information.

Re: How do groups work on Linux?

#48
post #42
post #34

Earlier quoted context omitted.

I've seen them ask how to restore execution permissions after `chmod a-x /bin/chmod'. I usually answer to those smartasses that I my favourite way is to run the very non-executable /bin/chmod without any file juggling. I'm yet to meet anybody who wasn't surprised that it's possible.

explain?

I'm a little surprised some smartypants hasn't come along and added a check to ld to prevent this from working, probably for "security" reasons.

I've known about this trick for a long time, but I've always thought its days were numbered.

Another way to solve the problem:

  scp unfuckedhost:/bin/chmod . 
  ./chmod (stuff)

Re: How do groups work on Linux?

#49
post #43
post #30

Earlier quoted context omitted.

> You said, and I quote, "it's Linux-specific" and I was demonstrating that it's not Linux-specific. You were attempting at demonstrating that the OS specific behaviour can also be exhibited elsewhere (also, you failed at that attempt; you haven't shown what group your shell belongs to). If you were to demonstrate that it's universal (as opposed to be OS specific), you would need to invoke some standard that describe…

> If you were to demonstrate that it's universal I really wasn't. I was just making a point that it's not just Linux-specific like you claimed. In fact if you re-read the thread you'd realise that nobody argued this behaviour was universal. Given the breadth of POSIX-like systems out there, I doubt anyone would dare make such a bold statement. So you're arguing against point that was never raised. > And by the way, f…

>> If you were to demonstrate that it's universal

> I really wasn't. I was just making a point that it's not just Linux-specific like you claimed.

I never claimed it's Linux only, only that there are other systems with different semantics.

>> And by the way, filesystems are typically implemented in kernel, so saying that it's not kernel that handles them is somewhat misguided.

> Well yes file systems generally are, except when they are not. For example ntfs-3g [...]

...except that FUSE is in-kernel mechanism to delegate VFS callbacks to userspace program. It's hard to argue in such a case that the work is not the kernel's responsibility.

> What the argument is about is whether the permission logic described (specifically the setgid bit on folders) is handled by the file system code or externally to the file system code in other parts of the kernel

Oh. This explains quite a bit, because I thought the argument was about whether the OS' usual semantics (group being inherited from directory or from EGID) are like that or not, not where in kernel this behaviour is coded.

> You're making the case that the behavior is independent to the file system implementation [...]

No, I'm making the case that Linux usually works one way, and BSD usually works the other way. I never claimed that anything was coded in any specific kernel subsystem, so don't add the statement yourself.

Re: How do groups work on Linux?

#50
post #29

"dr--r--r-- 1 bork awesome 6872 Sep 24 11:09 file.txt" This doesn't make sense.

It's kind of useless, but not illegal. You won't be able to stat/open any of the files in the directory, although anybody can read their names. Putting a .txt on a directory name is also perfectly legal and still in bad form.

I agree the most likely explanation is accidentally putting the d in there in the editing process.

Post reply on HN