summaryrefslogtreecommitdiffstats
path: root/src/partition/growfs.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-07-14 11:31:50 +0200
committerLennart Poettering <lennart@poettering.net>2022-07-14 11:31:50 +0200
commit12810f3abbc5e3d0d9a54495b79538cb18714180 (patch)
treea870b96f24a562aaf8816e8695ffce0dc5409801 /src/partition/growfs.c
parentgrowfs: insist we open a directory when opening fs mount point (diff)
downloadsystemd-12810f3abbc5e3d0d9a54495b79538cb18714180.tar.xz
systemd-12810f3abbc5e3d0d9a54495b79538cb18714180.zip
growfs: ensure that we operate on a block device before issuing a block ioctl
Similar to the previous commit: let's add extra safety so that we don't issue ioctls on the wrong type of inode.
Diffstat (limited to 'src/partition/growfs.c')
-rw-r--r--src/partition/growfs.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/partition/growfs.c b/src/partition/growfs.c
index d7069b8d08..cd85946812 100644
--- a/src/partition/growfs.c
+++ b/src/partition/growfs.c
@@ -198,6 +198,7 @@ static int run(int argc, char *argv[]) {
_cleanup_close_ int mountfd = -1, devfd = -1;
_cleanup_free_ char *devpath = NULL;
uint64_t size, newsize;
+ struct stat st;
dev_t devno;
int r;
@@ -233,10 +234,15 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to format device major/minor path: %m");
- devfd = open(devpath, O_RDONLY|O_CLOEXEC);
+ devfd = open(devpath, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (devfd < 0)
return log_error_errno(errno, "Failed to open \"%s\": %m", devpath);
+ if (fstat(devfd, &st) < 0)
+ return log_error_errno(r, "Failed to stat() device %s: %m", devpath);
+ if (!S_ISBLK(st.st_mode))
+ return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "Backing device of file system is not a block device, refusing.");
+
if (ioctl(devfd, BLKGETSIZE64, &size) != 0)
return log_error_errno(errno, "Failed to query size of \"%s\": %m", devpath);