Qualcomm Remote Filesystem Service Implementation
Go to file
Luca Weiss 695d0668ff storage: fix out of bounds read
Given that shadow_len is size_t (unsigned integer), subtracting a number
from it will make it wrap around < 0 and become positive again so the
subsequent "if (n > 0)" check will be mostly useless. On AOSP this makes
rmtfs segfault, on Linux distributions rmtfs happily reads beyond the
end of the buf.

Fix this by casting both parameters to ssize_t (which is signed) to
correctly use the if and not read beyond the end of shadow_buf.

Relevant trace using extra debug statements:
  storage_populate_shadow_buf: file=/dev/disk/by-partlabel/fsg shadow_buf=0xffffa5217060 shadow_len=0x280000
  <snip>
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fc00 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fe00 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280000 n=0x0 - don't read!
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280200 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280400 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280600 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280800 n=0x200
  <snip>

Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
2022-07-18 15:27:49 -05:00
.gitignore rmtfs.service: Add systemd service 2019-07-25 11:18:58 -07:00
Android.bp ANDROID: Add Android support 2020-02-03 09:13:59 -08:00
LICENSE rmtfs: Add missing LICENSE file 2016-06-02 10:29:40 -07:00
Makefile rmtfs.service: Add systemd service 2019-07-25 11:18:58 -07:00
qmi_rmtfs.c rmtfs: Migrate to new QMI encoder/decoder library 2018-02-01 02:09:35 +00:00
qmi_rmtfs.h rmtfs: Migrate to new QMI encoder/decoder library 2018-02-01 02:09:35 +00:00
qmi_rmtfs.qmi qmi_rmtfs: Update definition file to match the generated files 2018-02-01 04:39:46 +00:00
qmi_tlv.c rmtfs: Update tlv prototypes to accept message header 2016-02-08 11:49:55 -08:00
rmtfs.c Use fdatasync instead of O_SYNC on storage 2021-08-09 14:33:25 -07:00
rmtfs.h Use fdatasync instead of O_SYNC on storage 2021-08-09 14:33:25 -07:00
rmtfs.service.in rmtfs.service.in: Add RestartSec to 1 sec intervals 2020-01-30 22:09:44 -08:00
rproc.c rproc: Make start & stop threads detached 2020-12-07 08:42:05 -08:00
sharedmem.c sharedmem: Fix pointer arithmetic warnings. 2020-09-28 10:08:11 -05:00
storage.c storage: fix out of bounds read 2022-07-18 15:27:49 -05:00
util.c rmtfs: Initial rmtfs implementation 2016-02-07 09:32:14 -08:00
util.h rmtfs: Initial rmtfs implementation 2016-02-07 09:32:14 -08:00