Commit Graph

22 Commits

Author SHA1 Message Date
Kir Kolyshkin 8395a8b205 Fix and annotate Stat_t fields conversion
For struct Stat_t in syscall pkg:
 - Ino is always uint64;
 - Dev/Rdev can be uint64, uint32, or int32;
 - Nlink might be uint64, uint32, or uint16.

Fix the code accordingly, adding or removing typecasts where needed,
and annotating those with //nolint:unconvert to calm down the unconvert
linter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-01 16:18:55 -07:00
Minseo Kim 5015968dd8 pkg/system: fix `EOPNOTSUPP` to `ENOTSUP` for xattr syscalls
The lgetxattr(2), lsetxattr(2), and llistxattr(2) syscalls on Linux
return ENOTSUP instead of EOPNOTSUPP. The same applies to getxattr(2),
setxattr(2), and listxattr(2) on macOS.

Note that EOPNOTSUPP and ENOTSUP have the same value in Linux (refer to
errno(3)).

Signed-off-by: Minseo Kim <kimminss0@outlook.kr>
2024-11-29 18:32:32 +09:00
Kir Kolyshkin 83c0c077c5 all: remove old-style +build tags
Brought to you by

	go fix ./...

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-09-19 17:00:48 -07:00
Daniel J Walsh 3f8c0dc0de
Wrap errors properly with fmt.Errorf
Also returned errors should not begine with a capatalized errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-07-12 13:26:10 -04:00
Giuseppe Scrivano 35e013ae4b
chown: use Link instead of Chown for dup inodes
If the inode was already encountered and chowned, use link(2) instead
of chown(2).

This is needed when the underlying storage (as it could be overlay
with index=off) breaks the hard link on copy up.

https://github.com/containers/storage/pull/1144 added the initial
check.

Closes: https://github.com/containers/storage/issues/1257

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-06-14 22:38:25 +02:00
Sergio Lopez 7617ae34d8 Limited support for operating on images on macOS
Supporting macOS presents a number of challenges since the lack of
user namespaces means that operations that alter the ownership or
permissions on a file face harsh limitations, since are requested by
an unprivileged user that may need to potentially operate on arbitrary
uids/gids.

To overcome this challenges, we rely on the existing "forceMask"
feature to store the actual ownership and permission bits as an
extended attribute entry on each file.

In addition to automatically enabling "forceMask" when running on
macOS, we also need some minor changes to ensure the compatibility
with this OS. The most significant is the fact that, on macOS
SafeLchmod and SafeChmod also operate on the extended attributes, to
allow us to properly create the directories supporting the image.

With this changes in place, buildah is able to perform basic
operations on OCI images, such as downloading the image, creating a
working container, and removing them.

Signed-off-by: Sergio Lopez <slp@redhat.com>
2022-06-06 08:01:54 +02:00
Giuseppe Scrivano 28c166fa18
chown: use ToHostOverflow when chowning
when chowning an image, fall back to the overflow ID when a UID or GID
cannot be mapped to the target user namespace.

This ensures the chown driver works similar to what we do with
idmapped mounts when it is supported for overlay.

It is needed for CRI-O to support user namespaces in Kubernetes since
the Kubelet picks a static size for the user namespace and it might
break some images using IDs outside the picked range.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-04-28 17:38:35 +02:00
Robert Zaage 28f3ba9b89 fix storage-chown-by-maps doesnt handle -EOVERFLOW return by lgetxattr [Closes #1183]
Signed-off-by: Robert Zaage <robert@zaage.it>
2022-04-07 00:11:21 +02:00
Giuseppe Scrivano f59aa7a19f
drivers, chown: support chown of hard links
make sure the same inode is not chowned twice.  Track all the inodes
that are chowned and skip the same inode if it is encountered multiple
times.

Closes: https://github.com/containers/storage/issues/1143

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-21 15:35:39 +01:00
Giuseppe Scrivano e085aa8d0b
drivers, chown: move platformLChown to a struct
it is a preparatory commit.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-21 15:23:22 +01:00
Nalin Dahyabhai da8b28a5e6 chown: ignore both pkg/system.EOPNOTSUPP and pkg/system.ErrNotSupportedPlatform
Where we ignored a pkg/system.ErrNotSupportedPlatform error
from pkg/system.Lgetxattr(), also ignore ENOTSUP/EOPNOTSUPP, as we
already do elsewhere.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-03-10 14:21:40 -05:00
Daniel J Walsh 8d53e62ed7
Merge pull request #757 from kolyshkin/eintr
chmod/chown: handle EINTR
2020-10-30 10:08:52 -04:00
Kir Kolyshkin 800a569949
chown, chmod: retry on EINTR
The following failure has been observed in CI (see [1], [2]):

	storage-chown-by-maps: chown("/some/path"): interrupted system call

While chown and chmod should be auto-restartable by the kernel (provided
all the signal handlers are installed with SA_RESTART flag), it looks
like it is not always the case, or there might be some exclusions,
so this should be handled.

Surely, the possibility of getting EINTR is amplified since Go 1.14
introduced async preemptible goroutimes (see [3]), the feature that
is implemented via frequently sending signal 22 to all threads.

Add and use wrappers for Chmod and Lchown that retry on EINTR.

[1] https://github.com/containers/podman/issues/8152
[2] https://github.com/cri-o/cri-o/pull/4310#issuecomment-718361022
[3] https://golang.org/doc/go1.14#runtime

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-30 11:40:07 +01:00
Kir Kolyshkin 3a1bcb0e4b
graphdriver.platformLChown: improve errors
Functions from os package, such as os.Lchown or os.Chmod,
return an os.PathError which already contains the operation
and the file name, so there is no need to add them one more time.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-30 11:40:06 +01:00
Kir Kolyshkin 3bf3251882 system.*xattr: wrap errors into os.PathError
This way the error messages are more informative.

Convert all the users accordingly (assuming there are no users outside
of this repo).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-29 03:30:02 -07:00
Peter Hunt 12062560d1 platformLchown: use os package instead
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-10-22 16:55:15 -04:00
Kir Kolyshkin be28a551a5 drivers/platformLChown: rm os.Lstat call
This function is already called with the result from os.Lstat(),
so there's no need to do it again.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-11 08:36:34 -07:00
Kir Kolyshkin 1e8bf20d6b drivers/platformLChown: return early
This is purely aesthetical -- in case we can't get struct stat_t,
return early. This improves readability and decreases the indentation.

No functional change. Please review this with --ignore-space-change.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-11 08:36:34 -07:00
Sascha Grunert fd72b45a3f
Enable golint linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Daniel J Walsh 25d53dbc7b
Need to preserve the Xattr security.capabilty when chowning.
When we chown we not only loose the setuid flags but we also loose
the file capabilties.  This means in a user namespace when we chown
ping, it looses its filecap, which means it will not longer work.

This fix will check for the security capabilies and retain them if they
exist when chowning.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-05 09:12:11 -04:00
Giuseppe Scrivano 2df72f37c6
chown: restore SUID and SGID bits
be sure the SUID and SGID bits are not lost when we do
a chown.

Closes: https://github.com/containers/libpod/issues/1526

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-09-25 15:46:46 +02:00
Vincent Batts 019f3a4038
drivers: cross-platform chown
and a tidy-up of imports

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2018-05-30 17:05:51 -04:00