From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Julien Stephan <jstephan@baylibre.com>,
Nuno Sa <nuno.sa@analog.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Sasha Levin <sashal@kernel.org>,
jic23@kernel.org, linux-iio@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 50/83] driver: iio: add missing checks on iio_info's callback access
Date: Wed, 31 Jul 2024 20:18:05 -0400 [thread overview]
Message-ID: <20240801002107.3934037-50-sashal@kernel.org> (raw)
In-Reply-To: <20240801002107.3934037-1-sashal@kernel.org>
From: Julien Stephan <jstephan@baylibre.com>
[ Upstream commit c4ec8dedca961db056ec85cb7ca8c9f7e2e92252 ]
Some callbacks from iio_info structure are accessed without any check, so
if a driver doesn't implement them trying to access the corresponding
sysfs entries produce a kernel oops such as:
[ 2203.527791] Unable to handle kernel NULL pointer dereference at virtual address 00000000 when execute
[...]
[ 2203.783416] Call trace:
[ 2203.783429] iio_read_channel_info_avail from dev_attr_show+0x18/0x48
[ 2203.789807] dev_attr_show from sysfs_kf_seq_show+0x90/0x120
[ 2203.794181] sysfs_kf_seq_show from seq_read_iter+0xd0/0x4e4
[ 2203.798555] seq_read_iter from vfs_read+0x238/0x2a0
[ 2203.802236] vfs_read from ksys_read+0xa4/0xd4
[ 2203.805385] ksys_read from ret_fast_syscall+0x0/0x54
[ 2203.809135] Exception stack(0xe0badfa8 to 0xe0badff0)
[ 2203.812880] dfa0: 00000003 b6f10f80 00000003 b6eab000 00020000 00000000
[ 2203.819746] dfc0: 00000003 b6f10f80 7ff00000 00000003 00000003 00000000 00020000 00000000
[ 2203.826619] dfe0: b6e1bc88 bed80958 b6e1bc94 b6e1bcb0
[ 2203.830363] Code: bad PC value
[ 2203.832695] ---[ end trace 0000000000000000 ]---
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Julien Stephan <jstephan@baylibre.com>
Link: https://lore.kernel.org/r/20240530-iio-core-fix-segfault-v3-1-8b7cd2a03773@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/iio/industrialio-core.c | 7 ++++++-
drivers/iio/industrialio-event.c | 9 +++++++++
drivers/iio/inkern.c | 32 ++++++++++++++++++++++----------
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 5e1a85ca12119..121bde49ccb7d 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -752,9 +752,11 @@ static ssize_t iio_read_channel_info(struct device *dev,
INDIO_MAX_RAW_ELEMENTS,
vals, &val_len,
this_attr->address);
- else
+ else if (indio_dev->info->read_raw)
ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
&vals[0], &vals[1], this_attr->address);
+ else
+ return -EINVAL;
if (ret < 0)
return ret;
@@ -836,6 +838,9 @@ static ssize_t iio_read_channel_info_avail(struct device *dev,
int length;
int type;
+ if (!indio_dev->info->read_avail)
+ return -EINVAL;
+
ret = indio_dev->info->read_avail(indio_dev, this_attr->c,
&vals, &type, &length,
this_attr->address);
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 19f7a91157ee4..f67e4afa5f94b 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -285,6 +285,9 @@ static ssize_t iio_ev_state_store(struct device *dev,
if (ret < 0)
return ret;
+ if (!indio_dev->info->write_event_config)
+ return -EINVAL;
+
ret = indio_dev->info->write_event_config(indio_dev,
this_attr->c, iio_ev_attr_type(this_attr),
iio_ev_attr_dir(this_attr), val);
@@ -300,6 +303,9 @@ static ssize_t iio_ev_state_show(struct device *dev,
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int val;
+ if (!indio_dev->info->read_event_config)
+ return -EINVAL;
+
val = indio_dev->info->read_event_config(indio_dev,
this_attr->c, iio_ev_attr_type(this_attr),
iio_ev_attr_dir(this_attr));
@@ -318,6 +324,9 @@ static ssize_t iio_ev_value_show(struct device *dev,
int val, val2, val_arr[2];
int ret;
+ if (!indio_dev->info->read_event_value)
+ return -EINVAL;
+
ret = indio_dev->info->read_event_value(indio_dev,
this_attr->c, iio_ev_attr_type(this_attr),
iio_ev_attr_dir(this_attr), iio_ev_attr_info(this_attr),
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 7a1f6713318a3..b855565384757 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -562,6 +562,7 @@ EXPORT_SYMBOL_GPL(devm_iio_channel_get_all);
static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
enum iio_chan_info_enum info)
{
+ const struct iio_info *iio_info = chan->indio_dev->info;
int unused;
int vals[INDIO_MAX_RAW_ELEMENTS];
int ret;
@@ -573,15 +574,18 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
if (!iio_channel_has_info(chan->channel, info))
return -EINVAL;
- if (chan->indio_dev->info->read_raw_multi) {
- ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
- chan->channel, INDIO_MAX_RAW_ELEMENTS,
- vals, &val_len, info);
+ if (iio_info->read_raw_multi) {
+ ret = iio_info->read_raw_multi(chan->indio_dev,
+ chan->channel,
+ INDIO_MAX_RAW_ELEMENTS,
+ vals, &val_len, info);
*val = vals[0];
*val2 = vals[1];
+ } else if (iio_info->read_raw) {
+ ret = iio_info->read_raw(chan->indio_dev,
+ chan->channel, val, val2, info);
} else {
- ret = chan->indio_dev->info->read_raw(chan->indio_dev,
- chan->channel, val, val2, info);
+ return -EINVAL;
}
return ret;
@@ -801,11 +805,15 @@ static int iio_channel_read_avail(struct iio_channel *chan,
const int **vals, int *type, int *length,
enum iio_chan_info_enum info)
{
+ const struct iio_info *iio_info = chan->indio_dev->info;
+
if (!iio_channel_has_available(chan->channel, info))
return -EINVAL;
- return chan->indio_dev->info->read_avail(chan->indio_dev, chan->channel,
- vals, type, length, info);
+ if (iio_info->read_avail)
+ return iio_info->read_avail(chan->indio_dev, chan->channel,
+ vals, type, length, info);
+ return -EINVAL;
}
int iio_read_avail_channel_attribute(struct iio_channel *chan,
@@ -995,8 +1003,12 @@ EXPORT_SYMBOL_GPL(iio_get_channel_type);
static int iio_channel_write(struct iio_channel *chan, int val, int val2,
enum iio_chan_info_enum info)
{
- return chan->indio_dev->info->write_raw(chan->indio_dev,
- chan->channel, val, val2, info);
+ const struct iio_info *iio_info = chan->indio_dev->info;
+
+ if (iio_info->write_raw)
+ return iio_info->write_raw(chan->indio_dev,
+ chan->channel, val, val2, info);
+ return -EINVAL;
}
int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
--
2.43.0
next prev parent reply other threads:[~2024-08-01 0:24 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 0:17 [PATCH AUTOSEL 6.6 01/83] drm/amd/display: Assign linear_pitch_alignment even for VM Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 02/83] drm/amdgpu: fix overflowed array index read warning Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 03/83] drm/amdgpu/pm: Check the return value of smum_send_msg_to_smc Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 04/83] drm/amd/pm: fix warning using uninitialized value of max_vid_step Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 05/83] drm/amd/pm: Fix negative array index read Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 06/83] drm/amd/pm: fix the Out-of-bounds read warning Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 07/83] drm/amd/display: Check gpio_id before used as array index Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 08/83] drm/amd/display: Add NULL pointer and OVERRUN check within amdgpu_dm irq register Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 09/83] drm/amd/display: Stop amdgpu_dm initialize when stream nums greater than 6 Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 10/83] drm/amd/display: Check index for aux_rd_interval before using Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 11/83] drm/amd/display: Add array index check for hdcp ddc access Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 12/83] drm/amd/display: Check num_valid_sets before accessing reader_wm_sets[] Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 13/83] drm/amd/display: Skip updating link encoder for unknown eng_id Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 14/83] drm/amd/display: Check msg_id before processing transcation Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 15/83] drm/amd/display: Fix Coverity INTERGER_OVERFLOW within construct_integrated_info Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 16/83] drm/amd/display: Fix Coverity INTEGER_OVERFLOW within dal_gpio_service_create Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 17/83] drm/amd/display: Spinlock before reading event Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 18/83] drm/amd/display: Fix Coverity INTEGER_OVERFLOW within decide_fallback_link_setting_max_bw_policy Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 19/83] drm/amd/display: Skip inactive planes within ModeSupportAndSystemConfiguration Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 20/83] drm/amd/display: Fix index may exceed array range within fpu_update_bw_bounding_box Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 21/83] drm/amd/amdgpu: Check tbo resource pointer Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 22/83] drm/amdgpu: Fix out-of-bounds write warning Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 23/83] drm/amdkfd: Check debug trap enable before write dbg_ev_file Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 24/83] drm/amdgpu: Fix out-of-bounds read of df_v1_7_channel_number Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 25/83] drm/amdgpu: fix ucode out-of-bounds read warning Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 26/83] drm/amdgpu: fix mc_data " Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 27/83] drm/amdkfd: Reconcile the definition and use of oem_id in struct kfd_topology_device Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 28/83] wifi: ath12k: initialize 'ret' in ath12k_qmi_load_file_target_mem() Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 29/83] wifi: ath11k: initialize 'ret' in ath11k_qmi_load_file_target_mem() Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 30/83] drm/amdgpu/pm: Check input value for CUSTOM profile mode setting on legacy SOCs Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 31/83] drm/amdgpu: Fix the warning division or modulo by zero Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 32/83] drm/amdgpu: fix dereference after null check Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 33/83] drm/amdgpu: fix the waring dereferencing hive Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 34/83] drm/amdgpu: the warning dereferencing obj for nbio_v7_4 Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 35/83] drm/amdgpu: update type of buf size to u32 for eeprom functions Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 36/83] wifi: iwlwifi: fw: avoid bad FW config on RXQ DMA failure Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 37/83] cpufreq: scmi: Avoid overflow of target_freq in fast switch Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 38/83] bpf, net: Use DEV_STAT_INC() Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 39/83] PCI: al: Check IORESOURCE_BUS existence during probe Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 40/83] hwspinlock: Introduce hwspin_lock_bust() Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 41/83] soc: qcom: smem: Add qcom_smem_bust_hwspin_lock_by_host() Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 42/83] gpiolib: cdev: Add INIT_KFIFO() for linereq events Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 43/83] pwm: xilinx: Fix u32 overflow issue in 32-bit width PWM mode Sasha Levin
2024-08-01 0:17 ` [PATCH AUTOSEL 6.6 44/83] drm/amdgu: fix Unintentional integer overflow for mall size Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 45/83] smack: tcp: ipv4, fix incorrect labeling Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 46/83] drm/bridge: tc358767: Check if fully initialized before signalling HPD event via IRQ Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 47/83] EDAC/amd64: Check return value of amd_smn_read() Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 48/83] hwmon: (k10temp) " Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 49/83] wifi: cfg80211: make hash table duplicates more survivable Sasha Levin
2024-08-01 0:18 ` Sasha Levin [this message]
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 51/83] drm/amd/display: added NULL check at start of dc_validate_stream Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 52/83] drm/amd/display: Correct the defined value for AMDGPU_DMUB_NOTIFICATION_MAX Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 53/83] drm/amd/display: use preferred link settings for dp signal only Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 54/83] drm/amd/display: Check BIOS images before it is used Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 55/83] drm/amd/display: Skip wbscl_set_scaler_filter if filter is null Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 56/83] fou: remove warn in gue_gro_receive on unsupported protocol Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 57/83] ALSA: vmaster: Return error for invalid input values Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 58/83] ALSA: control: Apply sanity check of input values for user elements Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 59/83] wifi: ath12k: fix uninitialize symbol error on ath12k_peer_assoc_h_he() Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 60/83] wifi: ath12k: fix firmware crash due to invalid peer nss Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 61/83] ELF: fix kernel.randomize_va_space double read Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 62/83] accel/habanalabs/gaudi2: unsecure edma max outstanding register Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 63/83] x86/kmsan: Fix hook for unaligned accesses Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 64/83] udf: Avoid excessive partition lengths Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 65/83] riscv: mm: Take memory hotplug read-lock during kernel page table dump Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 66/83] usb: uas: set host status byte on data completion error Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 67/83] drm/amd/display: Run DC_LOG_DC after checking link->link_enc Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 68/83] drm/amd/display: Check HDCP returned status Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 69/83] drm/amd/display: Check denominator pbn_div before used Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 70/83] phy: zynqmp: Take the phy mutex in xlate Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 71/83] cgroup: Protect css->cgroup write under css_set_lock Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 72/83] um: line: always fill *error_out in setup_one_line() Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 73/83] devres: Initialize an uninitialized struct member Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 74/83] pci/hotplug/pnv_php: Fix hotplug driver crash on Powernv Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 75/83] virtio_ring: fix KMSAN error for premapped mode Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 76/83] wifi: rtw88: usb: schedule rx work after everything is set up Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 77/83] scsi: pm80xx: Set phy->enable_completion only when we wait for it Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 78/83] hwmon: (lm95234) Fix underflows seen when writing limit attributes Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 79/83] hwmon: (nct6775-core) " Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 80/83] hwmon: (w83627ehf) " Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 81/83] libbpf: Add NULL checks to bpf_object__{prev_map,next_map} Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 82/83] wifi: mwifiex: Do not return unused priv in mwifiex_get_priv_by_id() Sasha Levin
2024-08-01 0:18 ` [PATCH AUTOSEL 6.6 83/83] i3c: mipi-i3c-hci: Error out instead on BUG_ON() in IBI DMA setup Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240801002107.3934037-50-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=jic23@kernel.org \
--cc=jstephan@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox