Commit a4b1d50e authored by David Brownell's avatar David Brownell Committed by Linus Torvalds

RTCs: handle NVRAM better

Several of the RTC drivers are exporting binary "nvram" files in sysfs.  Such
NVRAM (or on many systems, EEPROM) data is often initialized during system
manufacture to hold data about identity (serial numbers, Ethernet addresses,
etc), configuration, calibration, and so forth.

This patch improves integrity and security of those files:

  - Correctly initializes the size in one of the two cases where
    that was not yet being done.

  - Improves system security/integrity by making this state not
    be world-writable by default.

Letting arbitrary userspace code mangle such state by default is at least Not
A Good Thing; and it could sometimes be worse, depending on the particular
data that might be corrupted.  (I disregard the paranoiac "don't let anyone
read it either" approach.  Anyone storing passwords in such memory doesn't
really care about security.)
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Acked-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: Torsten Ertbjerg Rasmussen <tr@newtec.dk>
Cc: Mark Zhan <rongkai.zhan@windriver.com>
Cc: Thomas Hommel <thomas.hommel@gefanuc.com>
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 779d2089
...@@ -291,7 +291,7 @@ static ssize_t ds1553_nvram_write(struct kobject *kobj, ...@@ -291,7 +291,7 @@ static ssize_t ds1553_nvram_write(struct kobject *kobj,
static struct bin_attribute ds1553_nvram_attr = { static struct bin_attribute ds1553_nvram_attr = {
.attr = { .attr = {
.name = "nvram", .name = "nvram",
.mode = S_IRUGO | S_IWUGO, .mode = S_IRUGO | S_IWUSR,
}, },
.size = RTC_OFFSET, .size = RTC_OFFSET,
.read = ds1553_nvram_read, .read = ds1553_nvram_read,
......
...@@ -160,10 +160,13 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj, ...@@ -160,10 +160,13 @@ static ssize_t ds1742_nvram_write(struct kobject *kobj,
static struct bin_attribute ds1742_nvram_attr = { static struct bin_attribute ds1742_nvram_attr = {
.attr = { .attr = {
.name = "nvram", .name = "nvram",
.mode = S_IRUGO | S_IWUGO, .mode = S_IRUGO | S_IWUSR,
}, },
.read = ds1742_nvram_read, .read = ds1742_nvram_read,
.write = ds1742_nvram_write, .write = ds1742_nvram_write,
/* REVISIT: size in sysfs won't match actual size... if it's
* not a constant, each RTC should have its own attribute.
*/
}; };
static int __devinit ds1742_rtc_probe(struct platform_device *pdev) static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
......
...@@ -353,11 +353,12 @@ static ssize_t m48t59_nvram_write(struct kobject *kobj, ...@@ -353,11 +353,12 @@ static ssize_t m48t59_nvram_write(struct kobject *kobj,
static struct bin_attribute m48t59_nvram_attr = { static struct bin_attribute m48t59_nvram_attr = {
.attr = { .attr = {
.name = "nvram", .name = "nvram",
.mode = S_IRUGO | S_IWUGO, .mode = S_IRUGO | S_IWUSR,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.read = m48t59_nvram_read, .read = m48t59_nvram_read,
.write = m48t59_nvram_write, .write = m48t59_nvram_write,
.size = M48T59_NVRAM_SIZE,
}; };
static int __devinit m48t59_rtc_probe(struct platform_device *pdev) static int __devinit m48t59_rtc_probe(struct platform_device *pdev)
......
...@@ -291,7 +291,7 @@ static ssize_t stk17ta8_nvram_write(struct kobject *kobj, ...@@ -291,7 +291,7 @@ static ssize_t stk17ta8_nvram_write(struct kobject *kobj,
static struct bin_attribute stk17ta8_nvram_attr = { static struct bin_attribute stk17ta8_nvram_attr = {
.attr = { .attr = {
.name = "nvram", .name = "nvram",
.mode = S_IRUGO | S_IWUGO, .mode = S_IRUGO | S_IWUSR,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.size = RTC_OFFSET, .size = RTC_OFFSET,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment