Commit 61912588 authored by Daniel Wagner's avatar Daniel Wagner Committed by Slava Monich

[connman] Make tethering work with newer kernels. JB#42830

nat: Set file offset back to 0 before writing ip_forward

Kernel versions >= 4.5 have changed the default behavior[1] for file
offset handling on crop/says fs to strict write position handling:

  Respect file position when writing sysctl strings. Multiple writes
  will append to the sysctl value buffer. Anything past the max length
  of the sysctl value buffer will be ignored. Writes to numeric sysctl
  entries must always be at file position 0 and the value must be
  fully contained in the buffer sent in the write syscall.

We first read from /proc/sys/net/ipv4/ip_forward before writing to the
file. Without the lseek to 0 first the write is silentenly ignored.

Bug report from Neil MacLeod <neil@nmacleod.com>.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?id=41662f5cc55335807d39404371cfcbb1909304c4
parent 2a67caf2
......@@ -54,6 +54,9 @@ static int enable_ip_forward(bool enable)
if (!value) {
if (read(f, &value, sizeof(value)) < 0)
value = 0;
if (lseek(f, 0, SEEK_SET) < 0)
return -errno;
}
if (enable) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment