Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_4CC00571772E3150D07C68D07C3CAC30790A@qq.com>
Date: Fri, 27 Aug 2021 12:48:41 +0800
From: "care" <2010267516@...com>
To: "musl" <musl@...ts.openwall.com>
Subject: What if the line in /proc/mounts is too long when calling getmntent_r?

Hi!
&nbsp; I want to get cgroups mount information from /proc/mounts, but when i calling&nbsp;struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen), i got nothing...
&nbsp; I run the program in a container.

&nbsp; alpine docker image:&nbsp; amd64/alpine:3.14
&nbsp; musl: 1.2.2
&nbsp; program:&nbsp;&nbsp;
#include <stdio.h&gt;#include <stdlib.h&gt;#include <mntent.h&gt;
#define CGROUP_MAX_VAL 512
int main(void){&nbsp; struct mntent ent;&nbsp; FILE *f;&nbsp; char buf[CGROUP_MAX_VAL];
&nbsp; f = setmntent("/proc/mounts", "r");&nbsp; if (f == NULL) {&nbsp; &nbsp; perror("setmntent");&nbsp; &nbsp; exit(1);&nbsp; }
&nbsp; while (getmntent_r(f, &amp;ent, buf, sizeof(buf)) != NULL) {&nbsp; &nbsp; printf("%s %s\n", ent.mnt_type, ent.mnt_opts);&nbsp; }
&nbsp; endmntent(f);}&nbsp; contents of file "/proc/mounts"
overlay / overlay rw,relatime,lowerdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/955/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/954/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/953/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/952/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/941/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/940/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/879/fs:/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/325/fs,upperdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/956/fs,workdir=/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/956/work 0 0proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0tmpfs /dev tmpfs rw,nosuid,size=65536k,mode=755 0 0devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666 0 0mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0sysfs /sys sysfs ro,nosuid,nodev,noexec,relatime 0 0tmpfs /sys/fs/cgroup tmpfs rw,nosuid,nodev,noexec,relatime,mode=755 0 0cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0...

&nbsp; I find the first line of the file /proc/mounts has 822 characters(In theory the 'overlay' could be even longer), more than CGROUP_MAX_VAL(512) defined in the proagram. Function fget in&nbsp;getmntent_r&nbsp;cann't get the whole line into linebuf, neither the character '\n'. And the function strchr(linebuf, '\n') returns false, causing program returnd.&nbsp;
&nbsp; The function&nbsp;struct mntent *getmntent(FILE *f)&nbsp;is a good chioce to deal this. But it can not be used in multiple threads, right?
&nbsp; Maybe the implementation of GNU libc&nbsp;struct mntent *__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)&nbsp;can be referenced.


&nbsp; thanks!
Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.