Show stats for protected mount points in diskspace plugin (#11767)
Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
Vladimir Kobal committed
Nov 9, 2021 at 20:28 UTC
f44dd56681bf6ece4129735b74d4b2baab729aab
1 file changed
+32
-1
collectors/diskspace.plugin/plugin_diskspace.c
+32
-1
@@ -83,6 +83,28 @@ int mount_point_cleanup(void *entry, void *data) {
83
return 0;
84
}
85
86
+// for the full list of protected mount points look at
87
+// https://github.com/systemd/systemd/blob/1eb3ef78b4df28a9e9f464714208f2682f957e36/src/core/namespace.c#L142-L149
88
+// https://github.com/systemd/systemd/blob/1eb3ef78b4df28a9e9f464714208f2682f957e36/src/core/namespace.c#L180-L194
89
+static const char *systemd_protected_mount_points[] = {
90
+ "/home",
91
+ "/root",
92
+ "/usr",
93
+ "/boot",
94
+ "/efi",
95
+ "/etc",
96
+ NULL
97
+};
98
+
99
+int mount_point_is_protected(char *mount_point)
100
+{
101
+ for (size_t i = 0; systemd_protected_mount_points[i] != NULL; i++)
102
+ if (!strcmp(mount_point, systemd_protected_mount_points[i]))
103
+ return 1;
104
+
105
+ return 0;
106
+}
107
+
108
static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
109
const char *family = mi->mount_point;
110
const char *disk = mi->persistent_id;
@@ -190,7 +212,12 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
212
if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
213
return;
214
193
- if(unlikely(mi->flags & MOUNTINFO_READONLY && !m->collected && m->do_space != CONFIG_BOOLEAN_YES && m->do_inodes != CONFIG_BOOLEAN_YES))
215
+ if (unlikely(
216
+ mi->flags & MOUNTINFO_READONLY &&
217
+ !mount_point_is_protected(mi->mount_point) &&
218
+ !m->collected &&
219
+ m->do_space != CONFIG_BOOLEAN_YES &&
220
+ m->do_inodes != CONFIG_BOOLEAN_YES))
221
return;
222
223
struct statvfs buff_statvfs;
@@ -389,6 +416,10 @@ void *diskspace_main(void *ptr) {
416
if(unlikely(mi->flags & (MOUNTINFO_IS_DUMMY | MOUNTINFO_IS_BIND)))
417
continue;
418
419
+ // exclude mounts made by ProtectHome and ProtectSystem systemd hardening options
420
+ if(mi->flags & MOUNTINFO_READONLY && !strcmp(mi->root, mi->mount_point))
421
+ continue;
422
+
423
do_disk_space_stats(mi, update_every);
424
if(unlikely(netdata_exit)) break;
425
}