From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
"H. Nikolaus Schaller" <hns@goldelico.com>,
Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Subject: [PATCH 4.9 104/107] power: generic-adc-battery: fix out-of-bounds write when copying channel properties
Date: Mon, 3 Sep 2018 18:57:08 +0200 [thread overview]
Message-ID: <20180903165643.861674468@linuxfoundation.org> (raw)
In-Reply-To: <20180903165637.293735109@linuxfoundation.org>
4.9-stable review patch. If anyone has any objections, please let me know.
------------------
From: H. Nikolaus Schaller <hns@goldelico.com>
commit 932d47448c3caa0fa99e84d7f5bc302aa286efd8 upstream.
We did have sporadic problems in the pinctrl framework during boot
where a pin group name unexpectedly became NULL leading to a NULL
dereference in strcmp.
Detailled analysis of the failing cases did reveal that there were
two devm allocated objects close to each other. The second one was
the affected group_desc in pinmux and the first one was the
psy_desc->properties buffer of the gab driver.
Review of the gab code showed that the address calculation for
one memcpy() is wrong. It does
properties + sizeof(type) * index
but C is defined to do the index multiplication already for
pointer + integer additions. Hence the factor was applied twice
and the memcpy() does write outside of the properties buffer.
Sometimes it happened to be the pinctrl and triggered the strcmp(NULL).
Anyways, it is overkill to use a memcpy() here instead of a simple
assignment, which is easier to read and has less risk for wrong
address calculations. So we change code to a simple assignment.
If we initialize the index to the first free location, we can even
remove the local variable 'properties'.
This bug seems to exist right from the beginning in 3.7-rc1 in
commit e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Cc: stable@vger.kernel.org
Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO")
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/power/supply/generic-adc-battery.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -243,10 +243,9 @@ static int gab_probe(struct platform_dev
struct power_supply_desc *psy_desc;
struct power_supply_config psy_cfg = {};
struct gab_platform_data *pdata = pdev->dev.platform_data;
- enum power_supply_property *properties;
int ret = 0;
int chan;
- int index = 0;
+ int index = ARRAY_SIZE(gab_props);
adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL);
if (!adc_bat) {
@@ -280,8 +279,6 @@ static int gab_probe(struct platform_dev
}
memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
- properties = (enum power_supply_property *)
- ((char *)psy_desc->properties + sizeof(gab_props));
/*
* getting channel from iio and copying the battery properties
@@ -295,15 +292,12 @@ static int gab_probe(struct platform_dev
adc_bat->channel[chan] = NULL;
} else {
/* copying properties for supported channels only */
- memcpy(properties + sizeof(*(psy_desc->properties)) * index,
- &gab_dyn_props[chan],
- sizeof(gab_dyn_props[chan]));
- index++;
+ psy_desc->properties[index++] = gab_dyn_props[chan];
}
}
/* none of the channels are supported so let's bail out */
- if (index == 0) {
+ if (index == ARRAY_SIZE(gab_props)) {
ret = -ENODEV;
goto second_mem_fail;
}
@@ -314,7 +308,7 @@ static int gab_probe(struct platform_dev
* as come channels may be not be supported by the device.So
* we need to take care of that.
*/
- psy_desc->num_properties = ARRAY_SIZE(gab_props) + index;
+ psy_desc->num_properties = index;
adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
if (IS_ERR(adc_bat->psy)) {
next prev parent reply other threads:[~2018-09-03 16:57 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-03 16:55 [PATCH 4.9 000/107] 4.9.125-stable review Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 001/107] vti6: fix PMTU caching and reporting on xmit Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 002/107] xfrm: fix missing dst_release() after policy blocking lbcast and multicast Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 003/107] xfrm: free skb if nlsk pointer is NULL Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 004/107] mac80211: add stations tied to AP_VLANs during hw reconfig Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 005/107] nl80211: Add a missing break in parse_station_flags Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 006/107] drm/bridge: adv7511: Reset registers on hotplug Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 007/107] scsi: libiscsi: fix possible NULL pointer dereference in case of TMF Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 008/107] drm/imx: imx-ldb: disable LDB on driver bind Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 009/107] drm/imx: imx-ldb: check if channel is enabled before printing warning Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 010/107] usb: gadget: r8a66597: Fix two possible sleep-in-atomic-context bugs in init_controller() Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 011/107] usb: gadget: r8a66597: Fix a possible sleep-in-atomic-context bugs in r8a66597_queue() Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 012/107] usb/phy: fix PPC64 build errors in phy-fsl-usb.c Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 014/107] usb: gadget: f_uac2: fix endianness of struct cntrl_*_lay3 Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 015/107] bpf, ppc64: fix unexpected r0=0 exit path inside bpf_xadd Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 016/107] tools/power turbostat: fix -S on UP systems Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 017/107] net: caif: Add a missing rcu_read_unlock() in caif_flow_cb Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 018/107] qed: Fix possible race for the link state value Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 019/107] qed: Correct Multicast API to reflect existence of 256 approximate buckets Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 020/107] atl1c: reserve min skb headroom Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 021/107] net: prevent ISA drivers from building on PPC32 Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 022/107] can: mpc5xxx_can: check of_iomap return before use Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 023/107] i2c: davinci: Avoid zero value of CLKH Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 024/107] perf/x86/amd/ibs: Dont access non-started event Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 025/107] media: staging: omap4iss: Include asm/cacheflush.h after generic includes Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 026/107] bnx2x: Fix invalid memory access in rss hash config path Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 028/107] net: axienet: Fix double deregister of mdio Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 029/107] x86/boot: Fix if_changed build flip/flop bug Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 030/107] fscache: Allow cancelled operations to be enqueued Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 031/107] cachefiles: Fix refcounting bug in backing-file read monitoring Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 032/107] cachefiles: Wait rather than BUGing on "Unexpected object collision" Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 033/107] selftests/ftrace: Add snapshot and tracing_on test case Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 034/107] zswap: re-check zswap_is_full() after do zswap_shrink() Greg Kroah-Hartman
2018-09-03 16:55 ` [PATCH 4.9 035/107] tools/power turbostat: Read extended processor family from CPUID Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 037/107] enic: handle mtu change for vf properly Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 038/107] arc: [plat-eznps] fix data type errors in platform headers Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 039/107] arc: fix build errors in arc/include/asm/delay.h Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 040/107] arc: fix type warnings in arc/mm/cache.c Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 041/107] squashfs metadata 2: electric boogaloo Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 043/107] drivers: net: lmc: fix case value for target abort error Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 044/107] memcg: remove memcg_cgroup::id from IDR on mem_cgroup_css_alloc() failure Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 045/107] scsi: fcoe: drop frames in ELS LOGO error path Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 046/107] scsi: fcoe: clear FC_RP_STARTED flags when receiving a LOGO Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 047/107] scsi: vmw_pvscsi: Return DID_RESET for status SAM_STAT_COMMAND_TERMINATED Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 048/107] mm/memory.c: check return value of ioremap_prot Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 049/107] sched/sysctl: Check user input value of sysctl_sched_time_avg Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 050/107] Cipso: cipso_v4_optptr enter infinite loop Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 051/107] mei: dont update offset in write Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 052/107] cifs: add missing debug entries for kconfig options Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 053/107] cifs: check kmalloc before use Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 054/107] smb3: enumerating snapshots was leaving part of the data off end Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 055/107] smb3: Do not send SMB3 SET_INFO if nothing changed Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 056/107] smb3: dont request leases in symlink creation and query Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 057/107] kprobes/arm64: Fix %p uses in error messages Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 058/107] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 059/107] s390/kvm: fix deadlock when killed by oom Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 060/107] ext4: check for NUL characters in extended attributes name Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 061/107] ext4: sysfs: print ext4_super_block fields as little-endian Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 062/107] ext4: reset error code in ext4_find_entry in fallback Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 063/107] staging: android: ion: fix ION_IOC_{MAP,SHARE} use-after-free Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 064/107] KVM: arm/arm64: Skip updating PTE entry if no change Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 065/107] KVM: arm/arm64: Skip updating PMD " Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 067/107] x86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 068/107] x86/speculation/l1tf: Fix off-by-one error when warning that system has too much RAM Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 069/107] x86/speculation/l1tf: Suggest what to do on systems with " Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 070/107] x86/process: Re-export start_thread() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 072/107] x86/kvm/vmx: Remove duplicate l1d flush definitions Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 073/107] fuse: Dont access pipe->buffers without pipe_lock() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 074/107] fuse: fix initial parallel dirops Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 075/107] fuse: fix double request_end() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 076/107] fuse: fix unlocked access to processing queue Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 077/107] fuse: umount should wait for all requests Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 078/107] fuse: Fix oops at process_init_reply() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 079/107] fuse: Add missed unlock_page() to fuse_readpages_fill() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 080/107] udl-kms: change down_interruptible to down Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 081/107] udl-kms: handle allocation failure Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 082/107] udl-kms: fix crash due to uninitialized memory Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 083/107] b43legacy/leds: Ensure NUL-termination of LED name string Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 084/107] b43/leds: " Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 085/107] ASoC: dpcm: dont merge format from invalid codec dai Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 086/107] ASoC: sirf: Fix potential NULL pointer dereference Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 088/107] x86/irqflags: Mark native_restore_fl extern inline Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 089/107] x86/spectre: Add missing family 6 check to microcode check Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 090/107] x86/speculation/l1tf: Increase l1tf memory limit for Nehalem+ Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 091/107] x86/entry/64: Wipe KASAN stack shadow before rewind_stack_do_exit() Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 092/107] s390: fix br_r1_trampoline for machines without exrl Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 093/107] s390/qdio: reset old sbal_state flags Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 094/107] s390/numa: move initial setup of node_to_cpumask_map Greg Kroah-Hartman
2018-09-03 16:56 ` [PATCH 4.9 095/107] s390/pci: fix out of bounds access during irq setup Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 096/107] kprobes: Make list and blacklist root user read only Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 097/107] MIPS: Correct the 64-bit DSP accumulator register size Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 098/107] MIPS: lib: Provide MIPS64r6 __multi3() for GCC < 7 Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 099/107] scsi: sysfs: Introduce sysfs_{un,}break_active_protection() Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 100/107] scsi: core: Avoid that SCSI device removal through sysfs triggers a deadlock Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 101/107] iscsi target: fix session creation failure handling Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 102/107] clk: rockchip: fix clk_i2sout parent selection bits on rk3399 Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 103/107] PM / clk: signedness bug in of_pm_clk_add_clks() Greg Kroah-Hartman
2018-09-03 16:57 ` Greg Kroah-Hartman [this message]
2018-09-03 16:57 ` [PATCH 4.9 105/107] power: generic-adc-battery: check for duplicate properties copied from iio channels Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 106/107] cdrom: Fix info leak/OOB read in cdrom_ioctl_drive_status Greg Kroah-Hartman
2018-09-03 16:57 ` [PATCH 4.9 107/107] staging: android: ion: check for kref overflow Greg Kroah-Hartman
2018-09-04 8:22 ` [PATCH 4.9 000/107] 4.9.125-stable review Naresh Kamboju
2018-09-04 19:33 ` Greg Kroah-Hartman
2018-09-04 19:29 ` Shuah Khan
2018-09-04 22:51 ` Guenter Roeck
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=20180903165643.861674468@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=hns@goldelico.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sebastian.reichel@collabora.co.uk \
--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;
as well as URLs for NNTP newsgroup(s).