<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/kernel/bpf, branch v4.9.78</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>bpf, array: fix overflow in max_entries and undefined behavior in index_mask</title>
<updated>2018-01-17T08:38:55+00:00</updated>
<author>
<name>Daniel Borkmann</name>
<email>daniel@iogearbox.net</email>
</author>
<published>2018-01-10T22:25:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=820ef2a0e54c4bed27758e393d09157d0d48c94c'/>
<id>820ef2a0e54c4bed27758e393d09157d0d48c94c</id>
<content type='text'>
commit bbeb6e4323dad9b5e0ee9f60c223dd532e2403b1 upstream.

syzkaller tried to alloc a map with 0xfffffffd entries out of a userns,
and thus unprivileged. With the recently added logic in b2157399cc98
("bpf: prevent out-of-bounds speculation") we round this up to the next
power of two value for max_entries for unprivileged such that we can
apply proper masking into potentially zeroed out map slots.

However, this will generate an index_mask of 0xffffffff, and therefore
a + 1 will let this overflow into new max_entries of 0. This will pass
allocation, etc, and later on map access we still enforce on the original
attr-&gt;max_entries value which was 0xfffffffd, therefore triggering GPF
all over the place. Thus bail out on overflow in such case.

Moreover, on 32 bit archs roundup_pow_of_two() can also not be used,
since fls_long(max_entries - 1) can result in 32 and 1UL &lt;&lt; 32 in 32 bit
space is undefined. Therefore, do this by hand in a 64 bit variable.

This fixes all the issues triggered by syzkaller's reproducers.

Fixes: b2157399cc98 ("bpf: prevent out-of-bounds speculation")
Reported-by: syzbot+b0efb8e572d01bce1ae0@syzkaller.appspotmail.com
Reported-by: syzbot+6c15e9744f75f2364773@syzkaller.appspotmail.com
Reported-by: syzbot+d2f5524fb46fd3b312ee@syzkaller.appspotmail.com
Reported-by: syzbot+61d23c95395cc90dbc2b@syzkaller.appspotmail.com
Reported-by: syzbot+0d363c942452cca68c01@syzkaller.appspotmail.com
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit bbeb6e4323dad9b5e0ee9f60c223dd532e2403b1 upstream.

syzkaller tried to alloc a map with 0xfffffffd entries out of a userns,
and thus unprivileged. With the recently added logic in b2157399cc98
("bpf: prevent out-of-bounds speculation") we round this up to the next
power of two value for max_entries for unprivileged such that we can
apply proper masking into potentially zeroed out map slots.

However, this will generate an index_mask of 0xffffffff, and therefore
a + 1 will let this overflow into new max_entries of 0. This will pass
allocation, etc, and later on map access we still enforce on the original
attr-&gt;max_entries value which was 0xfffffffd, therefore triggering GPF
all over the place. Thus bail out on overflow in such case.

Moreover, on 32 bit archs roundup_pow_of_two() can also not be used,
since fls_long(max_entries - 1) can result in 32 and 1UL &lt;&lt; 32 in 32 bit
space is undefined. Therefore, do this by hand in a 64 bit variable.

This fixes all the issues triggered by syzkaller's reproducers.

Fixes: b2157399cc98 ("bpf: prevent out-of-bounds speculation")
Reported-by: syzbot+b0efb8e572d01bce1ae0@syzkaller.appspotmail.com
Reported-by: syzbot+6c15e9744f75f2364773@syzkaller.appspotmail.com
Reported-by: syzbot+d2f5524fb46fd3b312ee@syzkaller.appspotmail.com
Reported-by: syzbot+61d23c95395cc90dbc2b@syzkaller.appspotmail.com
Reported-by: syzbot+0d363c942452cca68c01@syzkaller.appspotmail.com
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: prevent out-of-bounds speculation</title>
<updated>2018-01-17T08:38:55+00:00</updated>
<author>
<name>Alexei Starovoitov</name>
<email>ast@kernel.org</email>
</author>
<published>2018-01-08T01:33:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=a9bfac14cde2b481eeb0e64fbe15305df66ab32e'/>
<id>a9bfac14cde2b481eeb0e64fbe15305df66ab32e</id>
<content type='text'>
commit b2157399cc9898260d6031c5bfe45fe137c1fbe7 upstream.

Under speculation, CPUs may mis-predict branches in bounds checks. Thus,
memory accesses under a bounds check may be speculated even if the
bounds check fails, providing a primitive for building a side channel.

To avoid leaking kernel data round up array-based maps and mask the index
after bounds check, so speculated load with out of bounds index will load
either valid value from the array or zero from the padded area.

Unconditionally mask index for all array types even when max_entries
are not rounded to power of 2 for root user.
When map is created by unpriv user generate a sequence of bpf insns
that includes AND operation to make sure that JITed code includes
the same 'index &amp; index_mask' operation.

If prog_array map is created by unpriv user replace
  bpf_tail_call(ctx, map, index);
with
  if (index &gt;= max_entries) {
    index &amp;= map-&gt;index_mask;
    bpf_tail_call(ctx, map, index);
  }
(along with roundup to power 2) to prevent out-of-bounds speculation.
There is secondary redundant 'if (index &gt;= max_entries)' in the interpreter
and in all JITs, but they can be optimized later if necessary.

Other array-like maps (cpumap, devmap, sockmap, perf_event_array, cgroup_array)
cannot be used by unpriv, so no changes there.

That fixes bpf side of "Variant 1: bounds check bypass (CVE-2017-5753)" on
all architectures with and without JIT.

v2-&gt;v3:
Daniel noticed that attack potentially can be crafted via syscall commands
without loading the program, so add masking to those paths as well.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: John Fastabend &lt;john.fastabend@gmail.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[ Backported to 4.9 - gregkh ]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit b2157399cc9898260d6031c5bfe45fe137c1fbe7 upstream.

Under speculation, CPUs may mis-predict branches in bounds checks. Thus,
memory accesses under a bounds check may be speculated even if the
bounds check fails, providing a primitive for building a side channel.

To avoid leaking kernel data round up array-based maps and mask the index
after bounds check, so speculated load with out of bounds index will load
either valid value from the array or zero from the padded area.

Unconditionally mask index for all array types even when max_entries
are not rounded to power of 2 for root user.
When map is created by unpriv user generate a sequence of bpf insns
that includes AND operation to make sure that JITed code includes
the same 'index &amp; index_mask' operation.

If prog_array map is created by unpriv user replace
  bpf_tail_call(ctx, map, index);
with
  if (index &gt;= max_entries) {
    index &amp;= map-&gt;index_mask;
    bpf_tail_call(ctx, map, index);
  }
(along with roundup to power 2) to prevent out-of-bounds speculation.
There is secondary redundant 'if (index &gt;= max_entries)' in the interpreter
and in all JITs, but they can be optimized later if necessary.

Other array-like maps (cpumap, devmap, sockmap, perf_event_array, cgroup_array)
cannot be used by unpriv, so no changes there.

That fixes bpf side of "Variant 1: bounds check bypass (CVE-2017-5753)" on
all architectures with and without JIT.

v2-&gt;v3:
Daniel noticed that attack potentially can be crafted via syscall commands
without loading the program, so add masking to those paths as well.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: John Fastabend &lt;john.fastabend@gmail.com&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[ Backported to 4.9 - gregkh ]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: refactor fixup_bpf_calls()</title>
<updated>2018-01-17T08:38:55+00:00</updated>
<author>
<name>Alexei Starovoitov</name>
<email>ast@fb.com</email>
</author>
<published>2017-03-16T01:26:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=f55093dccd3ac90f003698fae7ecd75cf2862179'/>
<id>f55093dccd3ac90f003698fae7ecd75cf2862179</id>
<content type='text'>
commit 79741b3bdec01a8628368fbcfccc7d189ed606cb upstream.

reduce indent and make it iterate over instructions similar to
convert_ctx_accesses(). Also convert hard BUG_ON into soft verifier error.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[Backported to 4.9.y - gregkh]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 79741b3bdec01a8628368fbcfccc7d189ed606cb upstream.

reduce indent and make it iterate over instructions similar to
convert_ctx_accesses(). Also convert hard BUG_ON into soft verifier error.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[Backported to 4.9.y - gregkh]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: move fixup_bpf_calls() function</title>
<updated>2018-01-17T08:38:55+00:00</updated>
<author>
<name>Alexei Starovoitov</name>
<email>ast@fb.com</email>
</author>
<published>2017-03-16T01:26:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=28035366afe93f7bdb833a7867caccf4b7eda166'/>
<id>28035366afe93f7bdb833a7867caccf4b7eda166</id>
<content type='text'>
commit e245c5c6a5656e4d61aa7bb08e9694fd6e5b2b9d upstream.

no functional change.
move fixup_bpf_calls() to verifier.c
it's being refactored in the next patch

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[backported to 4.9 - gregkh]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;


</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit e245c5c6a5656e4d61aa7bb08e9694fd6e5b2b9d upstream.

no functional change.
move fixup_bpf_calls() to verifier.c
it's being refactored in the next patch

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Jiri Slaby &lt;jslaby@suse.cz&gt;
[backported to 4.9 - gregkh]
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;


</pre>
</div>
</content>
</entry>
<entry>
<title>bpf/verifier: Fix states_equal() comparison of pointer and UNKNOWN</title>
<updated>2017-12-29T16:43:00+00:00</updated>
<author>
<name>Ben Hutchings</name>
<email>ben@decadent.org.uk</email>
</author>
<published>2017-12-23T02:26:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=37435f7e80ef9adc32a69013c18f135e3f434244'/>
<id>37435f7e80ef9adc32a69013c18f135e3f434244</id>
<content type='text'>
An UNKNOWN_VALUE is not supposed to be derived from a pointer, unless
pointer leaks are allowed.  Therefore, states_equal() must not treat
a state with a pointer in a register as "equal" to a state with an
UNKNOWN_VALUE in that register.

This was fixed differently upstream, but the code around here was
largely rewritten in 4.14 by commit f1174f77b50c "bpf/verifier: rework
value tracking".  The bug can be detected by the bpf/verifier sub-test
"pointer/scalar confusion in state equality check (way 1)".

Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
Cc: Edward Cree &lt;ecree@solarflare.com&gt;
Cc: Jann Horn &lt;jannh@google.com&gt;
Cc: Alexei Starovoitov &lt;ast@kernel.org&gt;
Cc: Daniel Borkmann &lt;daniel@iogearbox.net&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
An UNKNOWN_VALUE is not supposed to be derived from a pointer, unless
pointer leaks are allowed.  Therefore, states_equal() must not treat
a state with a pointer in a register as "equal" to a state with an
UNKNOWN_VALUE in that register.

This was fixed differently upstream, but the code around here was
largely rewritten in 4.14 by commit f1174f77b50c "bpf/verifier: rework
value tracking".  The bug can be detected by the bpf/verifier sub-test
"pointer/scalar confusion in state equality check (way 1)".

Signed-off-by: Ben Hutchings &lt;ben@decadent.org.uk&gt;
Cc: Edward Cree &lt;ecree@solarflare.com&gt;
Cc: Jann Horn &lt;jannh@google.com&gt;
Cc: Alexei Starovoitov &lt;ast@kernel.org&gt;
Cc: Daniel Borkmann &lt;daniel@iogearbox.net&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: fix incorrect sign extension in check_alu_op()</title>
<updated>2017-12-25T13:23:47+00:00</updated>
<author>
<name>Daniel Borkmann</name>
<email>daniel@iogearbox.net</email>
</author>
<published>2017-12-22T15:29:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=3695b3b18519099224efbc5875569d2cb6da256d'/>
<id>3695b3b18519099224efbc5875569d2cb6da256d</id>
<content type='text'>
From: Jann Horn &lt;jannh@google.com&gt;

[ Upstream commit 95a762e2c8c942780948091f8f2a4f32fce1ac6f ]

Distinguish between
BPF_ALU64|BPF_MOV|BPF_K (load 32-bit immediate, sign-extended to 64-bit)
and BPF_ALU|BPF_MOV|BPF_K (load 32-bit immediate, zero-padded to 64-bit);
only perform sign extension in the first case.

Starting with v4.14, this is exploitable by unprivileged users as long as
the unprivileged_bpf_disabled sysctl isn't set.

Debian assigned CVE-2017-16995 for this issue.

v3:
 - add CVE number (Ben Hutchings)

Fixes: 484611357c19 ("bpf: allow access into map value arrays")
Signed-off-by: Jann Horn &lt;jannh@google.com&gt;
Acked-by: Edward Cree &lt;ecree@solarflare.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From: Jann Horn &lt;jannh@google.com&gt;

[ Upstream commit 95a762e2c8c942780948091f8f2a4f32fce1ac6f ]

Distinguish between
BPF_ALU64|BPF_MOV|BPF_K (load 32-bit immediate, sign-extended to 64-bit)
and BPF_ALU|BPF_MOV|BPF_K (load 32-bit immediate, zero-padded to 64-bit);
only perform sign extension in the first case.

Starting with v4.14, this is exploitable by unprivileged users as long as
the unprivileged_bpf_disabled sysctl isn't set.

Debian assigned CVE-2017-16995 for this issue.

v3:
 - add CVE number (Ben Hutchings)

Fixes: 484611357c19 ("bpf: allow access into map value arrays")
Signed-off-by: Jann Horn &lt;jannh@google.com&gt;
Acked-by: Edward Cree &lt;ecree@solarflare.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: reject out-of-bounds stack pointer calculation</title>
<updated>2017-12-25T13:23:47+00:00</updated>
<author>
<name>Daniel Borkmann</name>
<email>daniel@iogearbox.net</email>
</author>
<published>2017-12-22T15:29:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=d75d3ee237cee9068022117e059b64bbab617f3d'/>
<id>d75d3ee237cee9068022117e059b64bbab617f3d</id>
<content type='text'>
From: Jann Horn &lt;jannh@google.com&gt;

Reject programs that compute wildly out-of-bounds stack pointers.
Otherwise, pointers can be computed with an offset that doesn't fit into an
`int`, causing security issues in the stack memory access check (as well as
signed integer overflow during offset addition).

This is a fix specifically for the v4.9 stable tree because the mainline
code looks very different at this point.

Fixes: 7bca0a9702edf ("bpf: enhance verifier to understand stack pointer arithmetic")
Signed-off-by: Jann Horn &lt;jannh@google.com&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From: Jann Horn &lt;jannh@google.com&gt;

Reject programs that compute wildly out-of-bounds stack pointers.
Otherwise, pointers can be computed with an offset that doesn't fit into an
`int`, causing security issues in the stack memory access check (as well as
signed integer overflow during offset addition).

This is a fix specifically for the v4.9 stable tree because the mainline
code looks very different at this point.

Fixes: 7bca0a9702edf ("bpf: enhance verifier to understand stack pointer arithmetic")
Signed-off-by: Jann Horn &lt;jannh@google.com&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: fix branch pruning logic</title>
<updated>2017-12-25T13:23:47+00:00</updated>
<author>
<name>Daniel Borkmann</name>
<email>daniel@iogearbox.net</email>
</author>
<published>2017-12-22T15:29:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=7b5b73ea87a06236fa124bdebed1390d362d3439'/>
<id>7b5b73ea87a06236fa124bdebed1390d362d3439</id>
<content type='text'>
From: Alexei Starovoitov &lt;ast@fb.com&gt;

[ Upstream commit c131187db2d3fa2f8bf32fdf4e9a4ef805168467 ]

when the verifier detects that register contains a runtime constant
and it's compared with another constant it will prune exploration
of the branch that is guaranteed not to be taken at runtime.
This is all correct, but malicious program may be constructed
in such a way that it always has a constant comparison and
the other branch is never taken under any conditions.
In this case such path through the program will not be explored
by the verifier. It won't be taken at run-time either, but since
all instructions are JITed the malicious program may cause JITs
to complain about using reserved fields, etc.
To fix the issue we have to track the instructions explored by
the verifier and sanitize instructions that are dead at run time
with NOPs. We cannot reject such dead code, since llvm generates
it for valid C code, since it doesn't do as much data flow
analysis as the verifier does.

Fixes: 17a5267067f3 ("bpf: verifier (add verifier core)")
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From: Alexei Starovoitov &lt;ast@fb.com&gt;

[ Upstream commit c131187db2d3fa2f8bf32fdf4e9a4ef805168467 ]

when the verifier detects that register contains a runtime constant
and it's compared with another constant it will prune exploration
of the branch that is guaranteed not to be taken at runtime.
This is all correct, but malicious program may be constructed
in such a way that it always has a constant comparison and
the other branch is never taken under any conditions.
In this case such path through the program will not be explored
by the verifier. It won't be taken at run-time either, but since
all instructions are JITed the malicious program may cause JITs
to complain about using reserved fields, etc.
To fix the issue we have to track the instructions explored by
the verifier and sanitize instructions that are dead at run time
with NOPs. We cannot reject such dead code, since llvm generates
it for valid C code, since it doesn't do as much data flow
analysis as the verifier does.

Fixes: 17a5267067f3 ("bpf: verifier (add verifier core)")
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: adjust insn_aux_data when patching insns</title>
<updated>2017-12-25T13:23:47+00:00</updated>
<author>
<name>Daniel Borkmann</name>
<email>daniel@iogearbox.net</email>
</author>
<published>2017-12-22T15:29:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=565f012f5abb2d2bba8e03efcd1dba7577245011'/>
<id>565f012f5abb2d2bba8e03efcd1dba7577245011</id>
<content type='text'>
From: Alexei Starovoitov &lt;ast@fb.com&gt;

[ Upstream commit 8041902dae5299c1f194ba42d14383f734631009 ]

convert_ctx_accesses() replaces single bpf instruction with a set of
instructions. Adjust corresponding insn_aux_data while patching.
It's needed to make sure subsequent 'for(all insn)' loops
have matching insn and insn_aux_data.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
From: Alexei Starovoitov &lt;ast@fb.com&gt;

[ Upstream commit 8041902dae5299c1f194ba42d14383f734631009 ]

convert_ctx_accesses() replaces single bpf instruction with a set of
instructions. Adjust corresponding insn_aux_data while patching.
It's needed to make sure subsequent 'for(all insn)' loops
have matching insn and insn_aux_data.

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>bpf: fix lockdep splat</title>
<updated>2017-12-14T08:28:23+00:00</updated>
<author>
<name>Eric Dumazet</name>
<email>edumazet@google.com</email>
</author>
<published>2017-11-15T01:15:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=f45f4f8a7cd89570b987ff101bcc510e9cfc2a9a'/>
<id>f45f4f8a7cd89570b987ff101bcc510e9cfc2a9a</id>
<content type='text'>
[ Upstream commit 89ad2fa3f043a1e8daae193bcb5fe34d5f8caf28 ]

pcpu_freelist_pop() needs the same lockdep awareness than
pcpu_freelist_populate() to avoid a false positive.

 [ INFO: SOFTIRQ-safe -&gt; SOFTIRQ-unsafe lock order detected ]

 switchto-defaul/12508 [HC0[0]:SC0[6]:HE0:SE0] is trying to acquire:
  (&amp;htab-&gt;buckets[i].lock){......}, at: [&lt;ffffffff9dc099cb&gt;] __htab_percpu_map_update_elem+0x1cb/0x300

 and this task is already holding:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...}, at: [&lt;ffffffff9e135848&gt;] __dev_queue_xmit+0
x868/0x1240
 which would create a new lock dependency:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...} -&gt; (&amp;htab-&gt;buckets[i].lock){......}

 but this new dependency connects a SOFTIRQ-irq-safe lock:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...}
 ... which became SOFTIRQ-irq-safe at:
   [&lt;ffffffff9db5931b&gt;] __lock_acquire+0x42b/0x1f10
   [&lt;ffffffff9db5b32c&gt;] lock_acquire+0xbc/0x1b0
   [&lt;ffffffff9da05e38&gt;] _raw_spin_lock+0x38/0x50
   [&lt;ffffffff9e135848&gt;] __dev_queue_xmit+0x868/0x1240
   [&lt;ffffffff9e136240&gt;] dev_queue_xmit+0x10/0x20
   [&lt;ffffffff9e1965d9&gt;] ip_finish_output2+0x439/0x590
   [&lt;ffffffff9e197410&gt;] ip_finish_output+0x150/0x2f0
   [&lt;ffffffff9e19886d&gt;] ip_output+0x7d/0x260
   [&lt;ffffffff9e19789e&gt;] ip_local_out+0x5e/0xe0
   [&lt;ffffffff9e197b25&gt;] ip_queue_xmit+0x205/0x620
   [&lt;ffffffff9e1b8398&gt;] tcp_transmit_skb+0x5a8/0xcb0
   [&lt;ffffffff9e1ba152&gt;] tcp_write_xmit+0x242/0x1070
   [&lt;ffffffff9e1baffc&gt;] __tcp_push_pending_frames+0x3c/0xf0
   [&lt;ffffffff9e1b3472&gt;] tcp_rcv_established+0x312/0x700
   [&lt;ffffffff9e1c1acc&gt;] tcp_v4_do_rcv+0x11c/0x200
   [&lt;ffffffff9e1c3dc2&gt;] tcp_v4_rcv+0xaa2/0xc30
   [&lt;ffffffff9e191107&gt;] ip_local_deliver_finish+0xa7/0x240
   [&lt;ffffffff9e191a36&gt;] ip_local_deliver+0x66/0x200
   [&lt;ffffffff9e19137d&gt;] ip_rcv_finish+0xdd/0x560
   [&lt;ffffffff9e191e65&gt;] ip_rcv+0x295/0x510
   [&lt;ffffffff9e12ff88&gt;] __netif_receive_skb_core+0x988/0x1020
   [&lt;ffffffff9e130641&gt;] __netif_receive_skb+0x21/0x70
   [&lt;ffffffff9e1306ff&gt;] process_backlog+0x6f/0x230
   [&lt;ffffffff9e132129&gt;] net_rx_action+0x229/0x420
   [&lt;ffffffff9da07ee8&gt;] __do_softirq+0xd8/0x43d
   [&lt;ffffffff9e282bcc&gt;] do_softirq_own_stack+0x1c/0x30
   [&lt;ffffffff9dafc2f5&gt;] do_softirq+0x55/0x60
   [&lt;ffffffff9dafc3a8&gt;] __local_bh_enable_ip+0xa8/0xb0
   [&lt;ffffffff9db4c727&gt;] cpu_startup_entry+0x1c7/0x500
   [&lt;ffffffff9daab333&gt;] start_secondary+0x113/0x140

 to a SOFTIRQ-irq-unsafe lock:
  (&amp;head-&gt;lock){+.+...}
 ... which became SOFTIRQ-irq-unsafe at:
 ...  [&lt;ffffffff9db5971f&gt;] __lock_acquire+0x82f/0x1f10
   [&lt;ffffffff9db5b32c&gt;] lock_acquire+0xbc/0x1b0
   [&lt;ffffffff9da05e38&gt;] _raw_spin_lock+0x38/0x50
   [&lt;ffffffff9dc0b7fa&gt;] pcpu_freelist_pop+0x7a/0xb0
   [&lt;ffffffff9dc08b2c&gt;] htab_map_alloc+0x50c/0x5f0
   [&lt;ffffffff9dc00dc5&gt;] SyS_bpf+0x265/0x1200
   [&lt;ffffffff9e28195f&gt;] entry_SYSCALL_64_fastpath+0x12/0x17

 other info that might help us debug this:

 Chain exists of:
   dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2 --&gt; &amp;htab-&gt;buckets[i].lock --&gt; &amp;head-&gt;lock

  Possible interrupt unsafe locking scenario:

        CPU0                    CPU1
        ----                    ----
   lock(&amp;head-&gt;lock);
                                local_irq_disable();
                                lock(dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2);
                                lock(&amp;htab-&gt;buckets[i].lock);
   &lt;Interrupt&gt;
     lock(dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2);

  *** DEADLOCK ***

Fixes: e19494edab82 ("bpf: introduce percpu_freelist")
Signed-off-by: Eric Dumazet &lt;edumazet@google.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 89ad2fa3f043a1e8daae193bcb5fe34d5f8caf28 ]

pcpu_freelist_pop() needs the same lockdep awareness than
pcpu_freelist_populate() to avoid a false positive.

 [ INFO: SOFTIRQ-safe -&gt; SOFTIRQ-unsafe lock order detected ]

 switchto-defaul/12508 [HC0[0]:SC0[6]:HE0:SE0] is trying to acquire:
  (&amp;htab-&gt;buckets[i].lock){......}, at: [&lt;ffffffff9dc099cb&gt;] __htab_percpu_map_update_elem+0x1cb/0x300

 and this task is already holding:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...}, at: [&lt;ffffffff9e135848&gt;] __dev_queue_xmit+0
x868/0x1240
 which would create a new lock dependency:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...} -&gt; (&amp;htab-&gt;buckets[i].lock){......}

 but this new dependency connects a SOFTIRQ-irq-safe lock:
  (dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2){+.-...}
 ... which became SOFTIRQ-irq-safe at:
   [&lt;ffffffff9db5931b&gt;] __lock_acquire+0x42b/0x1f10
   [&lt;ffffffff9db5b32c&gt;] lock_acquire+0xbc/0x1b0
   [&lt;ffffffff9da05e38&gt;] _raw_spin_lock+0x38/0x50
   [&lt;ffffffff9e135848&gt;] __dev_queue_xmit+0x868/0x1240
   [&lt;ffffffff9e136240&gt;] dev_queue_xmit+0x10/0x20
   [&lt;ffffffff9e1965d9&gt;] ip_finish_output2+0x439/0x590
   [&lt;ffffffff9e197410&gt;] ip_finish_output+0x150/0x2f0
   [&lt;ffffffff9e19886d&gt;] ip_output+0x7d/0x260
   [&lt;ffffffff9e19789e&gt;] ip_local_out+0x5e/0xe0
   [&lt;ffffffff9e197b25&gt;] ip_queue_xmit+0x205/0x620
   [&lt;ffffffff9e1b8398&gt;] tcp_transmit_skb+0x5a8/0xcb0
   [&lt;ffffffff9e1ba152&gt;] tcp_write_xmit+0x242/0x1070
   [&lt;ffffffff9e1baffc&gt;] __tcp_push_pending_frames+0x3c/0xf0
   [&lt;ffffffff9e1b3472&gt;] tcp_rcv_established+0x312/0x700
   [&lt;ffffffff9e1c1acc&gt;] tcp_v4_do_rcv+0x11c/0x200
   [&lt;ffffffff9e1c3dc2&gt;] tcp_v4_rcv+0xaa2/0xc30
   [&lt;ffffffff9e191107&gt;] ip_local_deliver_finish+0xa7/0x240
   [&lt;ffffffff9e191a36&gt;] ip_local_deliver+0x66/0x200
   [&lt;ffffffff9e19137d&gt;] ip_rcv_finish+0xdd/0x560
   [&lt;ffffffff9e191e65&gt;] ip_rcv+0x295/0x510
   [&lt;ffffffff9e12ff88&gt;] __netif_receive_skb_core+0x988/0x1020
   [&lt;ffffffff9e130641&gt;] __netif_receive_skb+0x21/0x70
   [&lt;ffffffff9e1306ff&gt;] process_backlog+0x6f/0x230
   [&lt;ffffffff9e132129&gt;] net_rx_action+0x229/0x420
   [&lt;ffffffff9da07ee8&gt;] __do_softirq+0xd8/0x43d
   [&lt;ffffffff9e282bcc&gt;] do_softirq_own_stack+0x1c/0x30
   [&lt;ffffffff9dafc2f5&gt;] do_softirq+0x55/0x60
   [&lt;ffffffff9dafc3a8&gt;] __local_bh_enable_ip+0xa8/0xb0
   [&lt;ffffffff9db4c727&gt;] cpu_startup_entry+0x1c7/0x500
   [&lt;ffffffff9daab333&gt;] start_secondary+0x113/0x140

 to a SOFTIRQ-irq-unsafe lock:
  (&amp;head-&gt;lock){+.+...}
 ... which became SOFTIRQ-irq-unsafe at:
 ...  [&lt;ffffffff9db5971f&gt;] __lock_acquire+0x82f/0x1f10
   [&lt;ffffffff9db5b32c&gt;] lock_acquire+0xbc/0x1b0
   [&lt;ffffffff9da05e38&gt;] _raw_spin_lock+0x38/0x50
   [&lt;ffffffff9dc0b7fa&gt;] pcpu_freelist_pop+0x7a/0xb0
   [&lt;ffffffff9dc08b2c&gt;] htab_map_alloc+0x50c/0x5f0
   [&lt;ffffffff9dc00dc5&gt;] SyS_bpf+0x265/0x1200
   [&lt;ffffffff9e28195f&gt;] entry_SYSCALL_64_fastpath+0x12/0x17

 other info that might help us debug this:

 Chain exists of:
   dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2 --&gt; &amp;htab-&gt;buckets[i].lock --&gt; &amp;head-&gt;lock

  Possible interrupt unsafe locking scenario:

        CPU0                    CPU1
        ----                    ----
   lock(&amp;head-&gt;lock);
                                local_irq_disable();
                                lock(dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2);
                                lock(&amp;htab-&gt;buckets[i].lock);
   &lt;Interrupt&gt;
     lock(dev_queue-&gt;dev-&gt;qdisc_class ?: &amp;qdisc_tx_lock#2);

  *** DEADLOCK ***

Fixes: e19494edab82 ("bpf: introduce percpu_freelist")
Signed-off-by: Eric Dumazet &lt;edumazet@google.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@verizon.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
