* [PATCH AUTOSEL 6.14 16/29] iio: dac: adi-axi-dac: add cntrl chan check
[not found] <20250609134511.1342999-1-sashal@kernel.org>
@ 2025-06-09 13:44 ` Sasha Levin
2025-06-09 13:44 ` [PATCH AUTOSEL 6.14 18/29] iio: hid-sensor-prox: Add support for 16-bit report size Sasha Levin
1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2025-06-09 13:44 UTC (permalink / raw)
To: patches, stable
Cc: Angelo Dureghello, Nuno Sá, Jonathan Cameron, Sasha Levin,
lars, Michael.Hennerich, linux-iio
From: Angelo Dureghello <adureghello@baylibre.com>
[ Upstream commit 029035636de37395124a602c830152ef39a35fab ]
Add validity check on CNTRL_X channels (valid as 0 to 15).
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Link: https://patch.msgid.link/20250409-wip-bl-ad3552r-fixes-v5-1-fb429c3a6515@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
**YES**
This commit should be backported to stable kernel trees because it fixes
a real security vulnerability involving bounds checking of channel
numbers.
## Analysis of the Commit
### **Security Vulnerability Fixed**
The commit adds critical bounds checking to prevent out-of-bounds memory
access. Looking at the code changes:
1. **Defines maximum channel limit**: `#define AXI_DAC_CHAN_CNTRL_MAX
15`
2. **Adds validation in multiple functions**:
- `__axi_dac_frequency_get()`: `if (chan > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_scale_get()`: `if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_phase_get()`: `if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `__axi_dac_frequency_set()`: `if (chan > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_scale_set()`: `if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_phase_set()`: `if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_data_source_set()`: `if (chan > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
- `axi_dac_set_sample_rate()`: `if (chan > AXI_DAC_CHAN_CNTRL_MAX)
return -EINVAL;`
### **Why This is a Real Security Issue**
1. **Memory-mapped I/O vulnerability**: The register address calculation
`#define AXI_DAC_CHAN_CNTRL_1_REG(c) (0x0400 + (c) * 0x40)` uses
channel numbers directly. Without bounds checking, channel numbers >
15 could access memory outside the intended register space.
2. **User-accessible attack surface**: These functions are accessible
through sysfs interfaces and backend APIs, allowing userspace or
other kernel modules to potentially exploit the vulnerability.
3. **Potential for memory corruption**: Out-of-bounds register access
could corrupt adjacent memory-mapped regions, leading to system
instability or privilege escalation.
### **Comparison with Similar Commits**
Looking at the provided similar commits, this follows the same pattern
as Similar Commit #1 (Status: YES), which added interface busy checking
to avoid "possible issues." This commit similarly adds defensive bounds
checking to prevent memory safety issues.
Unlike Similar Commits #2, #3, #4, and #5 (Status: NO), which were non-
functional cleanups, refactoring, or new feature additions, this commit
addresses a concrete security vulnerability.
### **Backport Criteria Met**
This commit satisfies all stable tree criteria:
- ✅ **Fixes important security bug**: Prevents out-of-bounds memory
access
- ✅ **Small and contained**: Simple bounds checking additions
- ✅ **Clear side effects**: Minimal risk - only adds validation
- ✅ **No architectural changes**: Just adds safety checks
- ✅ **Critical subsystem**: IIO drivers are used in industrial/embedded
systems
- ✅ **Minimal regression risk**: Early validation with clear error
returns
The fix is straightforward, low-risk, and addresses a real vulnerability
that could affect systems using this FPGA-based DAC driver in production
environments.
drivers/iio/dac/adi-axi-dac.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index bcaf365feef42..3e00f60152284 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -84,6 +84,7 @@
#define AXI_DAC_CHAN_CNTRL_7_REG(c) (0x0418 + (c) * 0x40)
#define AXI_DAC_CHAN_CNTRL_7_DATA_SEL GENMASK(3, 0)
+#define AXI_DAC_CHAN_CNTRL_MAX 15
#define AXI_DAC_RD_ADDR(x) (BIT(7) | (x))
/* 360 degrees in rad */
@@ -186,6 +187,9 @@ static int __axi_dac_frequency_get(struct axi_dac_state *st, unsigned int chan,
u32 reg, raw;
int ret;
+ if (chan > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
if (!st->dac_clk) {
dev_err(st->dev, "Sampling rate is 0...\n");
return -EINVAL;
@@ -230,6 +234,9 @@ static int axi_dac_scale_get(struct axi_dac_state *st,
int ret, vals[2];
u32 reg, raw;
+ if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
if (tone_2)
reg = AXI_DAC_CHAN_CNTRL_3_REG(chan->channel);
else
@@ -264,6 +271,9 @@ static int axi_dac_phase_get(struct axi_dac_state *st,
u32 reg, raw, phase;
int ret, vals[2];
+ if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
if (tone_2)
reg = AXI_DAC_CHAN_CNTRL_4_REG(chan->channel);
else
@@ -291,6 +301,9 @@ static int __axi_dac_frequency_set(struct axi_dac_state *st, unsigned int chan,
u16 raw;
int ret;
+ if (chan > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
if (!sample_rate || freq > sample_rate / 2) {
dev_err(st->dev, "Invalid frequency(%u) dac_clk(%llu)\n",
freq, sample_rate);
@@ -342,6 +355,9 @@ static int axi_dac_scale_set(struct axi_dac_state *st,
u32 raw = 0, reg;
int ret;
+ if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
ret = iio_str_to_fixpoint(buf, 100000, &integer, &frac);
if (ret)
return ret;
@@ -385,6 +401,9 @@ static int axi_dac_phase_set(struct axi_dac_state *st,
u32 raw, reg;
int ret;
+ if (chan->channel > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
ret = iio_str_to_fixpoint(buf, 100000, &integer, &frac);
if (ret)
return ret;
@@ -493,6 +512,9 @@ static int axi_dac_data_source_set(struct iio_backend *back, unsigned int chan,
{
struct axi_dac_state *st = iio_backend_get_priv(back);
+ if (chan > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
+
switch (data) {
case IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE:
return regmap_update_bits(st->regmap,
@@ -521,6 +543,8 @@ static int axi_dac_set_sample_rate(struct iio_backend *back, unsigned int chan,
unsigned int freq;
int ret, tone;
+ if (chan > AXI_DAC_CHAN_CNTRL_MAX)
+ return -EINVAL;
if (!sample_rate)
return -EINVAL;
if (st->reg_config & AXI_DAC_CONFIG_DDS_DISABLE)
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH AUTOSEL 6.14 18/29] iio: hid-sensor-prox: Add support for 16-bit report size
[not found] <20250609134511.1342999-1-sashal@kernel.org>
2025-06-09 13:44 ` [PATCH AUTOSEL 6.14 16/29] iio: dac: adi-axi-dac: add cntrl chan check Sasha Levin
@ 2025-06-09 13:44 ` Sasha Levin
1 sibling, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2025-06-09 13:44 UTC (permalink / raw)
To: patches, stable
Cc: Zhang Lixu, Srinivas Pandruvada, Jonathan Cameron, Sasha Levin,
jikos, jic23, linux-input, linux-iio
From: Zhang Lixu <lixu.zhang@intel.com>
[ Upstream commit ad02ca57e44e9936fca5095840fad9d4b47c5559 ]
On Intel platforms, the HID_USAGE_SENSOR_HUMAN_PROXIMITY report size is 16
bits. This patch adds support for handling 16-bit report sizes for the
HID_USAGE_SENSOR_HUMAN_PROXIMITY usage in the HID sensor proximity driver.
Previously, the driver only supported 8-bit and 32-bit report sizes. With
this change, the driver can now correctly process 16-bit proximity data,
ensuring accurate human presence detection on platforms where this report
size is used.
Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://patch.msgid.link/20250317013634.4117399-1-lixu.zhang@intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Based on my analysis of the commit and the context provided, I'll now
provide my recommendation:
**YES**
## Extensive Analysis
### Code Change Analysis
The commit adds support for 16-bit report sizes in the HID sensor
proximity driver by adding a simple `case 2:` clause to the existing
switch statement in the `prox_capture_sample()` function:
```c
switch (raw_len) {
case 1:
prox_state->human_presence[chan] = *(u8 *)raw_data * multiplier;
return 0;
+case 2:
+ prox_state->human_presence[chan] = *(u16 *)raw_data * multiplier;
+ return 0;
case 4:
prox_state->human_presence[chan] = *(u32 *)raw_data * multiplier;
return 0;
}
```
### Why This Should Be Backported
1. **Important Bug Fix**: The commit message clearly states this is
needed for Intel platforms where `HID_USAGE_SENSOR_HUMAN_PROXIMITY`
uses 16-bit reports. Without this change, these platforms cannot
correctly process proximity data, making the sensor completely non-
functional for 16-bit report sizes.
2. **Minimal Risk and Scope**: The change is extremely small (3 lines
added) and follows the exact same pattern as existing 8-bit and
32-bit cases. It's confined to a single function and only affects the
data parsing path for proximity sensors.
3. **Pattern Consistency**: Looking at the grep results from other IIO
drivers, handling multiple data sizes (including 16-bit) in switch
statements is a common pattern throughout the IIO subsystem. This
change follows established conventions.
4. **Hardware Compatibility**: The commit enables proper functionality
on Intel platforms that use 16-bit proximity reports. This is a
hardware compatibility fix rather than a new feature.
5. **No Architectural Changes**: The change doesn't modify any APIs,
data structures, or architectural components - it simply extends the
existing data size handling logic.
6. **Similar Successful Backports**: Looking at the reference commits,
we see that Similar Commit #3 and #4 were both backported (Status:
YES), and both were fixes for scale/data handling issues in HID
sensor drivers. This commit follows the same pattern of fixing data
handling bugs.
7. **Clear Failure Mode**: Without this fix, Intel platforms with 16-bit
proximity reports would fail to capture proximity data, returning
`-EINVAL` and making the proximity sensor completely unusable.
8. **Industry-Standard Fix**: The commit comes from Intel (Zhang Lixu)
with acknowledgment from the HID sensor maintainer (Srinivas
Pandruvada), indicating this addresses a real hardware compatibility
issue.
### Risk Assessment
The risk is extremely low because:
- The change only affects the specific case where `raw_len == 2`
- Existing 8-bit and 32-bit handling remains unchanged
- The code follows the exact same pattern as existing cases
- No memory management or complex logic is involved
- Failure would be immediate and obvious (wrong data values)
This commit clearly meets the stable tree criteria: it fixes an
important hardware compatibility bug with minimal risk and no
architectural changes.
drivers/iio/light/hid-sensor-prox.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c
index 4c65b32d34ce4..46f788b0bc3e2 100644
--- a/drivers/iio/light/hid-sensor-prox.c
+++ b/drivers/iio/light/hid-sensor-prox.c
@@ -215,6 +215,9 @@ static int prox_capture_sample(struct hid_sensor_hub_device *hsdev,
case 1:
prox_state->human_presence[chan] = *(u8 *)raw_data * multiplier;
return 0;
+ case 2:
+ prox_state->human_presence[chan] = *(u16 *)raw_data * multiplier;
+ return 0;
case 4:
prox_state->human_presence[chan] = *(u32 *)raw_data * multiplier;
return 0;
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread