bpf: Fix the irq and nmi check in bpf_sk_storage for tracing usage
The intention of the current check is to avoid using bpf_sk_storage
in irq and nmi.  Jakub pointed out that the current check cannot
do that.  For example, in_serving_softirq() returns true
if the softirq handling is interrupted by hard irq.
Fixes: 8e4597c627 ("bpf: Allow using bpf_sk_storage in FENTRY/FEXIT/RAW_TP")
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201116200113.2868539-1-kafai@fb.com
			
			
This commit is contained in:
		
				
					committed by
					
						
						Alexei Starovoitov
					
				
			
			
				
	
			
			
			
						parent
						
							024cd2cbd1
						
					
				
				
					commit
					b93ef089d3
				
			@@ -415,7 +415,7 @@ static bool bpf_sk_storage_tracing_allowed(const struct bpf_prog *prog)
 | 
			
		||||
BPF_CALL_4(bpf_sk_storage_get_tracing, struct bpf_map *, map, struct sock *, sk,
 | 
			
		||||
	   void *, value, u64, flags)
 | 
			
		||||
{
 | 
			
		||||
	if (!in_serving_softirq() && !in_task())
 | 
			
		||||
	if (in_irq() || in_nmi())
 | 
			
		||||
		return (unsigned long)NULL;
 | 
			
		||||
 | 
			
		||||
	return (unsigned long)____bpf_sk_storage_get(map, sk, value, flags);
 | 
			
		||||
@@ -424,7 +424,7 @@ BPF_CALL_4(bpf_sk_storage_get_tracing, struct bpf_map *, map, struct sock *, sk,
 | 
			
		||||
BPF_CALL_2(bpf_sk_storage_delete_tracing, struct bpf_map *, map,
 | 
			
		||||
	   struct sock *, sk)
 | 
			
		||||
{
 | 
			
		||||
	if (!in_serving_softirq() && !in_task())
 | 
			
		||||
	if (in_irq() || in_nmi())
 | 
			
		||||
		return -EPERM;
 | 
			
		||||
 | 
			
		||||
	return ____bpf_sk_storage_delete(map, sk);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user