Skip to content

Commit d453332

Browse files
jmberg-intelgregkh
authored andcommitted
devcoredump: provide a one-way disable function
Since device/firmware coredumps can contain private data, it can be desirable to turn them off unconditionally to be certain that no such data will be collected by the system. To achieve this, provide a "disabled" sysfs class attribute that can only be changed from 0 to 1 and not back. Upon disabling, discard existing coredumps and stop storing new ones. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e135303 commit d453332

1 file changed

Lines changed: 48 additions & 8 deletions

File tree

‎drivers/base/devcoredump.c‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#include <linux/fs.h>
3232
#include <linux/workqueue.h>
3333

34+
static struct class devcd_class;
35+
36+
/* global disable flag, for security purposes */
37+
static bool devcd_disabled;
38+
3439
/* if data isn't read by userspace after 5 minutes then delete it */
3540
#define DEVCD_TIMEOUT (HZ * 60 * 5)
3641

@@ -121,11 +126,51 @@ static const struct attribute_group *devcd_dev_groups[] = {
121126
&devcd_dev_group, NULL,
122127
};
123128

129+
static int devcd_free(struct device *dev, void *data)
130+
{
131+
struct devcd_entry *devcd = dev_to_devcd(dev);
132+
133+
flush_delayed_work(&devcd->del_wk);
134+
return 0;
135+
}
136+
137+
static ssize_t disabled_show(struct class *class, struct class_attribute *attr,
138+
char *buf)
139+
{
140+
return sprintf(buf, "%d\n", devcd_disabled);
141+
}
142+
143+
static ssize_t disabled_store(struct class *class, struct class_attribute *attr,
144+
const char *buf, size_t count)
145+
{
146+
long tmp = simple_strtol(buf, NULL, 10);
147+
148+
/*
149+
* This essentially makes the attribute write-once, since you can't
150+
* go back to not having it disabled. This is intentional, it serves
151+
* as a system lockdown feature.
152+
*/
153+
if (tmp != 1)
154+
return -EINVAL;
155+
156+
devcd_disabled = true;
157+
158+
class_for_each_device(&devcd_class, NULL, NULL, devcd_free);
159+
160+
return count;
161+
}
162+
163+
static struct class_attribute devcd_class_attrs[] = {
164+
__ATTR_RW(disabled),
165+
__ATTR_NULL
166+
};
167+
124168
static struct class devcd_class = {
125169
.name = "devcoredump",
126170
.owner = THIS_MODULE,
127171
.dev_release = devcd_dev_release,
128172
.dev_groups = devcd_dev_groups,
173+
.class_attrs = devcd_class_attrs,
129174
};
130175

131176
static ssize_t devcd_readv(char *buffer, loff_t offset, size_t count,
@@ -192,6 +237,9 @@ void dev_coredumpm(struct device *dev, struct module *owner,
192237
struct devcd_entry *devcd;
193238
struct device *existing;
194239

240+
if (devcd_disabled)
241+
goto free;
242+
195243
existing = class_find_device(&devcd_class, NULL, dev,
196244
devcd_match_failing);
197245
if (existing) {
@@ -249,14 +297,6 @@ static int __init devcoredump_init(void)
249297
}
250298
__initcall(devcoredump_init);
251299

252-
static int devcd_free(struct device *dev, void *data)
253-
{
254-
struct devcd_entry *devcd = dev_to_devcd(dev);
255-
256-
flush_delayed_work(&devcd->del_wk);
257-
return 0;
258-
}
259-
260300
static void __exit devcoredump_exit(void)
261301
{
262302
class_for_each_device(&devcd_class, NULL, NULL, devcd_free);

0 commit comments

Comments
 (0)