mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 00:20:32 +00:00
firmware: arm_scmi: Harden accesses to the sensor domains
[ Upstream commit 76f89c9547
]
Accessing sensor domains descriptors by the index upon the SCMI drivers
requests through the SCMI sensor operations interface can potentially
lead to out-of-bound violations if the SCMI driver misbehave.
Add an internal consistency check before any such domains descriptors
accesses.
Link: https://lore.kernel.org/r/20220817172731.1185305-4-cristian.marussi@arm.com
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
41bf1b0ad9
commit
8e880f3094
1 changed files with 18 additions and 4 deletions
|
@ -762,6 +762,10 @@ static int scmi_sensor_config_get(const struct scmi_protocol_handle *ph,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct scmi_xfer *t;
|
struct scmi_xfer *t;
|
||||||
|
struct sensors_info *si = ph->get_priv(ph);
|
||||||
|
|
||||||
|
if (sensor_id >= si->num_sensors)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_GET,
|
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_GET,
|
||||||
sizeof(__le32), sizeof(__le32), &t);
|
sizeof(__le32), sizeof(__le32), &t);
|
||||||
|
@ -771,7 +775,6 @@ static int scmi_sensor_config_get(const struct scmi_protocol_handle *ph,
|
||||||
put_unaligned_le32(sensor_id, t->tx.buf);
|
put_unaligned_le32(sensor_id, t->tx.buf);
|
||||||
ret = ph->xops->do_xfer(ph, t);
|
ret = ph->xops->do_xfer(ph, t);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
struct sensors_info *si = ph->get_priv(ph);
|
|
||||||
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
||||||
|
|
||||||
*sensor_config = get_unaligned_le64(t->rx.buf);
|
*sensor_config = get_unaligned_le64(t->rx.buf);
|
||||||
|
@ -788,6 +791,10 @@ static int scmi_sensor_config_set(const struct scmi_protocol_handle *ph,
|
||||||
int ret;
|
int ret;
|
||||||
struct scmi_xfer *t;
|
struct scmi_xfer *t;
|
||||||
struct scmi_msg_sensor_config_set *msg;
|
struct scmi_msg_sensor_config_set *msg;
|
||||||
|
struct sensors_info *si = ph->get_priv(ph);
|
||||||
|
|
||||||
|
if (sensor_id >= si->num_sensors)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_SET,
|
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_SET,
|
||||||
sizeof(*msg), 0, &t);
|
sizeof(*msg), 0, &t);
|
||||||
|
@ -800,7 +807,6 @@ static int scmi_sensor_config_set(const struct scmi_protocol_handle *ph,
|
||||||
|
|
||||||
ret = ph->xops->do_xfer(ph, t);
|
ret = ph->xops->do_xfer(ph, t);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
struct sensors_info *si = ph->get_priv(ph);
|
|
||||||
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
||||||
|
|
||||||
s->sensor_config = sensor_config;
|
s->sensor_config = sensor_config;
|
||||||
|
@ -831,8 +837,11 @@ static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph,
|
||||||
int ret;
|
int ret;
|
||||||
struct scmi_xfer *t;
|
struct scmi_xfer *t;
|
||||||
struct scmi_msg_sensor_reading_get *sensor;
|
struct scmi_msg_sensor_reading_get *sensor;
|
||||||
|
struct scmi_sensor_info *s;
|
||||||
struct sensors_info *si = ph->get_priv(ph);
|
struct sensors_info *si = ph->get_priv(ph);
|
||||||
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
|
||||||
|
if (sensor_id >= si->num_sensors)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
ret = ph->xops->xfer_get_init(ph, SENSOR_READING_GET,
|
ret = ph->xops->xfer_get_init(ph, SENSOR_READING_GET,
|
||||||
sizeof(*sensor), 0, &t);
|
sizeof(*sensor), 0, &t);
|
||||||
|
@ -841,6 +850,7 @@ static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph,
|
||||||
|
|
||||||
sensor = t->tx.buf;
|
sensor = t->tx.buf;
|
||||||
sensor->id = cpu_to_le32(sensor_id);
|
sensor->id = cpu_to_le32(sensor_id);
|
||||||
|
s = si->sensors + sensor_id;
|
||||||
if (s->async) {
|
if (s->async) {
|
||||||
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
|
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
|
||||||
ret = ph->xops->do_xfer_with_response(ph, t);
|
ret = ph->xops->do_xfer_with_response(ph, t);
|
||||||
|
@ -895,9 +905,13 @@ scmi_sensor_reading_get_timestamped(const struct scmi_protocol_handle *ph,
|
||||||
int ret;
|
int ret;
|
||||||
struct scmi_xfer *t;
|
struct scmi_xfer *t;
|
||||||
struct scmi_msg_sensor_reading_get *sensor;
|
struct scmi_msg_sensor_reading_get *sensor;
|
||||||
|
struct scmi_sensor_info *s;
|
||||||
struct sensors_info *si = ph->get_priv(ph);
|
struct sensors_info *si = ph->get_priv(ph);
|
||||||
struct scmi_sensor_info *s = si->sensors + sensor_id;
|
|
||||||
|
|
||||||
|
if (sensor_id >= si->num_sensors)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
s = si->sensors + sensor_id;
|
||||||
if (!count || !readings ||
|
if (!count || !readings ||
|
||||||
(!s->num_axis && count > 1) || (s->num_axis && count > s->num_axis))
|
(!s->num_axis && count > 1) || (s->num_axis && count > s->num_axis))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
Loading…
Reference in a new issue