Skip to content

Fix potential out-of-bounds error in some drivers

Markus Burri dri-devel linux-gpio linux-iio linuxppc-dev lkml llvm oe-kbuild-all 4 versions – Applied

Status from this message: Applied to the fixes-togreg branch of iio.git.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest6 patches 10 repliesApplied
  2. v31 patch 4 repliesSuperseded
  3. v21 patch 1 replySuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch4 repliesSuperseded

Changes in v4 from the cover letter

* Revert the decrement of accepted size by one character
* Added patches for drivers with the same pattern

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/6iio: backend: fix out-of-bound writedrivers/iio/industrialio-backend.c+4 -12 replies
2/6accel/ivpu: Use effective buffer size for zero terminatordrivers/accel/ivpu/ivpu_debugfs.c+1 -12 replies
3/6iio: fix potential out-of-bound writedrivers/iio/industrialio-core.c+4 -12 replies
4/6gpio: fix potential out-of-bound writedrivers/gpio/gpio-virtuser.c+10 -21 reply
5/6powerpc/eeh: fix potential OoBarch/powerpc/kernel/eeh.c+6 -11 reply
6/6powerpc/eeh-powernv: fix potential OoBarch/powerpc/platforms/powernv/eeh-powernv.c+6 -11 reply

Reviews trailers per patch

3 of 6 patches have a Reviewed-by or Acked-by.

PatchJacek LawrynowiczMahesh Salgaonkar
1/6
2/6R-b
3/6
4/6
5/6A-b
6/6A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/6] Fix potential out-of-bounds error in some drivers

Several drivers are using debugfs and follow the same pattern.

A buffer is created on the stack with a limited size to copy the given data from user space. The copy is performed using simple_write_to_buffer. This function limits the input according to the specified buffer size, but it does not write a string terminator if the buffer is truncated. Therefore, the driver adds this zero terminator afterward. Unfortunately, the original buffer size is used as an index, which can lead to an out-of-bounds error.

This patch set fixes this issue in all the drivers I have detected so far. The fix is to return an error in case of an unexpectedly long buffer being received and to use the effective written size for the zero terminator for consistency.

Changes in V4:
* Revert the decrement of accepted size by one character
* Added patches for drivers with the same pattern

Changes in V3:
* Decrement accepted size by one character according to feedback

Changes in V2:
* Use effective written size as index instead of original size

---
[V3] https://lore.kernel.org/lkml/[email protected]/
[V2] https://lore.kernel.org/lkml/[email protected]/
[V1] https://lore.kernel.org/lkml/[email protected]/

Markus Burri (6):
iio: backend: fix out-of-bound write
accel/ivpu: Use effective buffer size for zero terminator
iio: fix potential out-of-bound write
gpio: fix potential out-of-bound write powerpc/eeh: fix potential OoB powerpc/eeh-powernv: fix potential OoB

 arch/powerpc/kernel/eeh.c                    |  7 ++++++-
 arch/powerpc/platforms/powernv/eeh-powernv.c |  7 ++++++-
 drivers/accel/ivpu/ivpu_debugfs.c            |  2 +-
 drivers/gpio/gpio-virtuser.c                 | 12 ++++++++++--
 drivers/iio/industrialio-backend.c           |  5 ++++-
 drivers/iio/industrialio-core.c              |  5 ++++-
 6 files changed, 31 insertions(+), 7 deletions(-)

base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e

Signature · 1 line
2.39.5