X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=drivers%2Fchar%2Fnvram.c;h=5eb83c3ca20de35be340031015a93495ae19e12b;hb=0f4533979473a456a8adb3869365e12c7a99cf65;hp=7cf4518c030f2b3a9293c23dd599643739758d1c;hpb=83cb16727085b18191f45eb0ede6bf1f97d67a7a;p=mirror_ubuntu-jammy-kernel.git diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index 7cf4518c030f..5eb83c3ca20d 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c @@ -110,6 +110,7 @@ #include #include #include +#include #include @@ -263,10 +264,16 @@ static ssize_t nvram_write(struct file *file, const char __user *buf, unsigned char contents[NVRAM_BYTES]; unsigned i = *ppos; unsigned char *tmp; - int len; - len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count; - if (copy_from_user(contents, buf, len)) + if (i >= NVRAM_BYTES) + return 0; /* Past EOF */ + + if (count > NVRAM_BYTES - i) + count = NVRAM_BYTES - i; + if (count > NVRAM_BYTES) + return -EFAULT; /* Can't happen, but prove it to gcc */ + + if (copy_from_user(contents, buf, count)) return -EFAULT; spin_lock_irq(&rtc_lock); @@ -274,7 +281,7 @@ static ssize_t nvram_write(struct file *file, const char __user *buf, if (!__nvram_check_checksum()) goto checksum_err; - for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp) + for (tmp = contents; count--; ++i, ++tmp) __nvram_write_byte(*tmp, i); __nvram_set_checksum();