Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2641840imm; Sun, 12 Aug 2018 20:05:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyDIsyAMZenJaMpRDG5s3elmehrfDQnfQYbOxOAWsrUEuJoTPBuXDHPhlmymtYpSuRh6OUA X-Received: by 2002:a65:40cd:: with SMTP id u13-v6mr15694083pgp.334.1534129520200; Sun, 12 Aug 2018 20:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534129520; cv=none; d=google.com; s=arc-20160816; b=YCpyu5N+HjfPa+l+VDrT92gu73vJY5DJjgBnIDGuXZh2B87fbHkR9pOvNz4+2In6JL 5IgmxX7fjyt8UGNZmkFhrPgJ3KbWQX9L2N6COOQB2pPFTUanKo5+olgl5y0QX2Ex9aWh A/Ui6uM2KA0NXt3m4kS0nf1Mi65k5oBCOWNHQTHIZSAmQSosGOg/v8knskrvCZ0Xst+2 MBIpiuiZXrXpFSVaxtO4mGySwzwfzLUB/RockGtoMqt/aI1Hc/NOtONUq6KeEvvgepmT AxmfzgtFbWGOwNXONOvUMjoK33LZLdz3HOf57LU7VitLtEcDp3zQFpKBbPyCfGEq1Xh7 HchA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=paGM/ud2yD4rfZafqMldUHK2rdIiO/acUnYq7yhjIyk=; b=Phaxe0nYtGbYb2Cs3Ke+rWiyNwKljvGS3ocxj3Kz5cOIh/b68ZRIHrM3geu3028XWy A4Nbkzzoer5eWjKV6pnpWdg2rvTxap13pNEY/Jadq+rSs6g/r3rHhwGhbfi5pWr8blI+ tOlXQ8kDo8zCeTmPQDwDwknsJ5dwqBhTFlye2mOliCiEleQajgS9Ch+rl1OlA5Tur969 EOpPFh2hE12gG5VU2fO6qc4LoXrE+cvqUJEXHcla/jh4tkfjeW1Pqv6O+AxJV9h2IepA 1u7mQtKjqjlvUKdv2Omel5hR65MIDP+7M6J8NY0yX3earhD20DLoq7bbLvDKe1X3+u29 2mKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cJxd3e07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t16-v6si16367119pgi.457.2018.08.12.20.05.02; Sun, 12 Aug 2018 20:05:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cJxd3e07; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726837AbeHMF2r (ORCPT + 99 others); Mon, 13 Aug 2018 01:28:47 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43770 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbeHMF2r (ORCPT ); Mon, 13 Aug 2018 01:28:47 -0400 Received: by mail-pf1-f194.google.com with SMTP id j26-v6so6991094pfi.10; Sun, 12 Aug 2018 19:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=paGM/ud2yD4rfZafqMldUHK2rdIiO/acUnYq7yhjIyk=; b=cJxd3e07wTNsGIyNT94s5K2pJfcJKLk3e9pgHahzVn/J8bbG9aP9Qj9lqBs9lpNwvA 8mkaoHt7VFYOzoDTXAy7HZxJX0xV0h6FU+HMgJQ76m8RaFZMYZ9YJ2jABfOEPm1HdBER fE2IX5zPoiWGmX/YNVCVuJi2h6Tu59nVplZ8cFx/KWJp+CpykduEEjj0hVic0p+DKora fF8nt/iiklfAQKaeHZg5AQyRanLSs/mwcjboPUbUKG+cg59kQmfopTFbTgKtAW/ucTx5 h/VdFVHnytZb0WkFrx72UV2MRr9C5GZDlOmKlTrStKzL7k65DqDHAtTy52gTotRI2FK7 uLcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=paGM/ud2yD4rfZafqMldUHK2rdIiO/acUnYq7yhjIyk=; b=GdAc4Ckn2U7FLduF+t1mv0xLDg5B/s0soblXT1318tZUGiqPT4KAloSqK07CQXt6xH bTB2hAViIEjqJOBC5PUmTpEmuEH7sgMoRIpEuJjS/MuehLH2//kcDx05CPE3MtV29tH3 5DuNdCgHUafvlnoawX/uPt7cTe6BjSyJrg+KFG9iXqQXrKFBE/XQPv8Wq1mRlSw9w0Re 8bYlEFOiDdW7tPoFtzWDAL5pmUqn5fU7nbIBrVSf+k+e6KOPOLvPUQOOalMfGL3EJJU5 T/G48NfC9aWeiaAEOxosczfP8DO7CVozgFkLaZn5nIdzVMa4olucTzo/2dGgZaTsZKqo +NzQ== X-Gm-Message-State: AOUpUlGO4iiig4FUvRADJFkuiHxUsofxZ5I3U6O94oE7pH/5bjZ7zZJb QS5pAHBWJgqZ1lTrUzJxKOU= X-Received: by 2002:a63:5964:: with SMTP id j36-v6mr15521846pgm.222.1534128518137; Sun, 12 Aug 2018 19:48:38 -0700 (PDT) Received: from ?IPv6:2402:f000:1:1501:200:5efe:166.111.71.57? ([2402:f000:1:1501:200:5efe:a66f:4739]) by smtp.gmail.com with ESMTPSA id f19-v6sm26228706pfd.147.2018.08.12.19.48.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 19:48:37 -0700 (PDT) Subject: Re: [BUG] bpf: syscall: a possible sleep-in-atomic-context bug in map_update_elem() To: Y Song Cc: Daniel Borkmann , Alexei Starovoitov , netdev , Linux Kernel Mailing List , Jesper Dangaard Brouer References: <65830741-bf35-4d32-e365-c32fc17c25cb@gmail.com> <97aa2e6b-1863-f123-af2c-24a2e6333ba5@iogearbox.net> <4f9a083d-1498-8cfb-b54c-614abccb193e@gmail.com> From: Jia-Ju Bai Message-ID: Date: Mon, 13 Aug 2018 10:48:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/8/11 13:01, Y Song wrote: > On Fri, Aug 10, 2018 at 6:57 PM, Jia-Ju Bai wrote: >> >> On 2018/8/10 22:22, Daniel Borkmann wrote: >>> On 08/10/2018 04:07 PM, Jia-Ju Bai wrote: >>>> The kernel may sleep with holding a rcu read lock. >>>> >>>> The function call paths (from bottom to top) in Linux-4.16 are: >>>> >>>> [FUNC] kmalloc(GFP_KERNEL) >>>> kernel/kthread.c, 283: kmalloc in __kthread_create_on_node >>>> kernel/kthread.c, 365: __kthread_create_on_node in kthread_create_on_node >>>> kernel/bpf/cpumap.c, 368: kthread_create_on_node in __cpu_map_entry_alloc >>>> kernel/bpf/cpumap.c, 490: __cpu_map_entry_alloc in cpu_map_update_elem >>>> kernel/bpf/syscall.c, 724: [FUNC_PTR]cpu_map_update_elem in >>>> map_update_elem >>>> kernel/bpf/syscall.c, 723: rcu_read_lock in map_update_elem >>>> >>>> Note that [FUNC_PTR] means a function pointer call is used. >>>> >>>> I do not find a good way to fix it, so I only report. >>>> This is found by my static analysis tool (DSAC). > Maybe your static analysis tool have false positives in this case? > >>> Thanks for the report Jia-Ju! In the map_update_elem() from syscall >>> path there's a check map->map_type == BPF_MAP_TYPE_CPUMAP, where we >>> call the cpumap's map->ops->map_update_elem() while /not/ being under >>> rcu_read_lock() as in other cases, so looks okay to me. Could you point >>> out the case for being under rcu_read_lock() more specifically which >>> the tool found? >> >> Thanks for your reply :) >> My tool cannot accurately track the case of map->map_type at present... >> >> According to my code review, there is a indeed check on line 697 in >> Linux-4.16: >> else if (map->map_type == BPF_MAP_TYPE_CPUMAP) { >> err = map->ops->map_update_elem(map, key, value, attr->flags); >> goto out; >> } >> But there is a call to map->ops->map_update_elem() that is under >> rcu_read_lock on line 724: >> rcu_read_lock(); >> err = map->ops->map_update_elem(map, key, value, attr->flags); >> rcu_read_unlock(); >> >> So I think if map->map_type is not equal to BPF_MAP_TYPE_CPUMAP, >> map->ops->map_update_elem() can still be called under rcu_read_lock, is it >> right? > map->ops->map_update_elem() can be called under rcu_read_lock(), but > since it is not type cpumap, the function should not be cpu_map_update_elem(). > Could you double check your static analysis tool? Thanks for your reply :) I have checked the code again, and find that my report is not correct here. It is because that my tool does not handle the context of function pointer assignment. Best wishes, Jia-Ju Bai