Skip to content

Commit 76f89c9

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Harden accesses to the sensor domains
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>
1 parent 1ecb7d2 commit 76f89c9

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

drivers/firmware/arm_scmi/sensors.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,10 @@ static int scmi_sensor_config_get(const struct scmi_protocol_handle *ph,
762762
{
763763
int ret;
764764
struct scmi_xfer *t;
765+
struct sensors_info *si = ph->get_priv(ph);
766+
767+
if (sensor_id >= si->num_sensors)
768+
return -EINVAL;
765769

766770
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_GET,
767771
sizeof(__le32), sizeof(__le32), &t);
@@ -771,7 +775,6 @@ static int scmi_sensor_config_get(const struct scmi_protocol_handle *ph,
771775
put_unaligned_le32(sensor_id, t->tx.buf);
772776
ret = ph->xops->do_xfer(ph, t);
773777
if (!ret) {
774-
struct sensors_info *si = ph->get_priv(ph);
775778
struct scmi_sensor_info *s = si->sensors + sensor_id;
776779

777780
*sensor_config = get_unaligned_le64(t->rx.buf);
@@ -788,6 +791,10 @@ static int scmi_sensor_config_set(const struct scmi_protocol_handle *ph,
788791
int ret;
789792
struct scmi_xfer *t;
790793
struct scmi_msg_sensor_config_set *msg;
794+
struct sensors_info *si = ph->get_priv(ph);
795+
796+
if (sensor_id >= si->num_sensors)
797+
return -EINVAL;
791798

792799
ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_SET,
793800
sizeof(*msg), 0, &t);
@@ -800,7 +807,6 @@ static int scmi_sensor_config_set(const struct scmi_protocol_handle *ph,
800807

801808
ret = ph->xops->do_xfer(ph, t);
802809
if (!ret) {
803-
struct sensors_info *si = ph->get_priv(ph);
804810
struct scmi_sensor_info *s = si->sensors + sensor_id;
805811

806812
s->sensor_config = sensor_config;
@@ -831,8 +837,11 @@ static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph,
831837
int ret;
832838
struct scmi_xfer *t;
833839
struct scmi_msg_sensor_reading_get *sensor;
840+
struct scmi_sensor_info *s;
834841
struct sensors_info *si = ph->get_priv(ph);
835-
struct scmi_sensor_info *s = si->sensors + sensor_id;
842+
843+
if (sensor_id >= si->num_sensors)
844+
return -EINVAL;
836845

837846
ret = ph->xops->xfer_get_init(ph, SENSOR_READING_GET,
838847
sizeof(*sensor), 0, &t);
@@ -841,6 +850,7 @@ static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph,
841850

842851
sensor = t->tx.buf;
843852
sensor->id = cpu_to_le32(sensor_id);
853+
s = si->sensors + sensor_id;
844854
if (s->async) {
845855
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
846856
ret = ph->xops->do_xfer_with_response(ph, t);
@@ -895,9 +905,13 @@ scmi_sensor_reading_get_timestamped(const struct scmi_protocol_handle *ph,
895905
int ret;
896906
struct scmi_xfer *t;
897907
struct scmi_msg_sensor_reading_get *sensor;
908+
struct scmi_sensor_info *s;
898909
struct sensors_info *si = ph->get_priv(ph);
899-
struct scmi_sensor_info *s = si->sensors + sensor_id;
900910

911+
if (sensor_id >= si->num_sensors)
912+
return -EINVAL;
913+
914+
s = si->sensors + sensor_id;
901915
if (!count || !readings ||
902916
(!s->num_axis && count > 1) || (s->num_axis && count > s->num_axis))
903917
return -EINVAL;

0 commit comments

Comments
 (0)