Avoid buffer overruns in applesmc driver

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJZc2EoAAoJEMsfJm/On5mBR2UP/jOnU/HiMHJz4xSSXWDWWufo
 SldKOFKIQrLmcjU3nIrAlnQR0mNo0kfYpofcqHZQ56Mgs0LM0FqJ7rMNPTuIQECp
 i1sJFjE8Zo8hDjuxysVOhqUyxXUSLeNP6a9ox6wjNxzn6YbjoiBhpEu51CIdN3u3
 nRhx+qD7E8bQw86E+vk1lK92aH8oQPB/PfQpA/wNmu9wDzqIf/m9tDbTQ22tLgpI
 RRqszMNDcAfzaiPZq8edoSMkLfBdEkpRBtkDqncqD4nrLsisICRI1+OdGCUCyr1P
 2AeA/IsTuDj2WyJmJN6oV+WywTnQfvTsXNmgRUmElObQVu4digai840u+DlPCUPx
 N2rQNFgCmVQXmoPH/Xn0UEJXyszyWDfg4Ky7CJOBn3pCR8ia4Ft+hfwmfNDmnbZO
 o09SiYXAh1nkUsDIMokB6bBHAfzaKZrGVZtqb4birKNIwGxfvkEWiKBZGMe/9+yn
 NEQ/9vKQqpC3OuNglrwKDt/mvCFN+EHMbKAElYCRs9Aix6HQWpK9Vys5I4Kj4awo
 jILbRLf4N6BkobgJ1BKw7OTHEST5pRnU4E2VZ/BSbg6eXaKaKUGwgzQu0c6Zglgq
 0UJTyh+jSOsFVSTVeHnKyCpldQC5QcpeGteFWeJC0774FKBvXAwcWxH4jTNBauA2
 dAA4VdJeDZg1vjTeyTPn
 =3eXw
 -----END PGP SIGNATURE-----

Merge tag 'hwmon-for-linus-v4.13-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon fix from Guenter Roeck:
 "Avoid buffer overruns in applesmc driver"

* tag 'hwmon-for-linus-v4.13-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: (applesmc) Avoid buffer overruns
This commit is contained in:
Linus Torvalds 2017-07-22 09:25:00 -07:00
commit 4b162c530d

View file

@ -566,6 +566,8 @@ static int applesmc_init_smcreg_try(void)
if (ret)
return ret;
s->fan_count = tmp[0];
if (s->fan_count > 10)
s->fan_count = 10;
ret = applesmc_get_lower_bound(&s->temp_begin, "T");
if (ret)
@ -811,7 +813,8 @@ static ssize_t applesmc_show_fan_speed(struct device *dev,
char newkey[5];
u8 buffer[2];
sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
scnprintf(newkey, sizeof(newkey), fan_speed_fmt[to_option(attr)],
to_index(attr));
ret = applesmc_read_key(newkey, buffer, 2);
speed = ((buffer[0] << 8 | buffer[1]) >> 2);
@ -834,7 +837,8 @@ static ssize_t applesmc_store_fan_speed(struct device *dev,
if (kstrtoul(sysfsbuf, 10, &speed) < 0 || speed >= 0x4000)
return -EINVAL; /* Bigger than a 14-bit value */
sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
scnprintf(newkey, sizeof(newkey), fan_speed_fmt[to_option(attr)],
to_index(attr));
buffer[0] = (speed >> 6) & 0xff;
buffer[1] = (speed << 2) & 0xff;
@ -903,7 +907,7 @@ static ssize_t applesmc_show_fan_position(struct device *dev,
char newkey[5];
u8 buffer[17];
sprintf(newkey, FAN_ID_FMT, to_index(attr));
scnprintf(newkey, sizeof(newkey), FAN_ID_FMT, to_index(attr));
ret = applesmc_read_key(newkey, buffer, 16);
buffer[16] = 0;
@ -1116,7 +1120,8 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
}
for (i = 0; i < num; i++) {
node = &grp->nodes[i];
sprintf(node->name, grp->format, i + 1);
scnprintf(node->name, sizeof(node->name), grp->format,
i + 1);
node->sda.index = (grp->option << 16) | (i & 0xffff);
node->sda.dev_attr.show = grp->show;
node->sda.dev_attr.store = grp->store;