Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp139915ybt; Tue, 7 Jul 2020 18:26:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRRzqhPEsjeyFK5Us8l56DedIeayjWFFk+00F56nXa/S4QP5hpfK3rzdPjWIcdDegwi6mp X-Received: by 2002:aa7:d458:: with SMTP id q24mr11129127edr.25.1594171597732; Tue, 07 Jul 2020 18:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594171597; cv=none; d=google.com; s=arc-20160816; b=jggF5XVkPk2WQxm6zoAcYD7zf3/bJSsx2cm2OHmug0oyH0yI0VdYJzICqCpWWgnq8q rA7aQLTyMfO76kjDKL2uA1R4t/eW9UAfpvH9xaQ+kWCZO489h5bGJPHKVgI5OMan6hoC h61xKZvLAXCfORwpQuNOzLEgatYP4RTyV7AE8gB2UOdFKdmmXXEWoOe48ik5tqUgAS8q dyRvuP63CtzuerZAmkPpN4Kxogx2UqXOAusAJHkpmopn1ch2ddxic8gGjrv3yfUL+5tB zu4oFFAN96Yxs2yJYDoyPButJI2DGPq28SY8Ccx1xI072/4LD79l4YeS43+KWbtGb27m iIoA== 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; bh=uhXQFE3P/OMTe2ST4dAYlyPeRRmwc3UKygXwg0CEW3Y=; b=AdDBp+eCZ+2MebW92vzoCARURH4hWhlZ1F3Z4QY1DAcvuDlCkiWx4ty2+rFsaCEq+j u0fWGKFOGkDyq5wPJpjqbnXBm6Nz9AKtV1chZiMPq0H9YzYGdGFQVHCtrM9ggzFI9Fcm K5KpdizNaCUwV+prbJo7ZMazX4c7tQ94VMVa4nKMz7V2lS6S4OS8lrNsJOB4YSiSv95g CXKNcigoYNmLKS8aN6k4tyhF6j7dq5rko1GRqFyryovQ9Qn9Pj1ep75sBoVrSc0jgrFj Wk6Px/HCaRTA9M/WMVkN2VoaBuxNDuqOLdHyim87/35/dtm8Zx0yFw6bq4zZtzzJCrdZ Pugw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=N+DK1E+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si15517675ejq.136.2020.07.07.18.26.15; Tue, 07 Jul 2020 18:26:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=N+DK1E+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728768AbgGHBHN (ORCPT + 99 others); Tue, 7 Jul 2020 21:07:13 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:48180 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728201AbgGHBHN (ORCPT ); Tue, 7 Jul 2020 21:07:13 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 068121lT157159; Wed, 8 Jul 2020 01:07:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=uhXQFE3P/OMTe2ST4dAYlyPeRRmwc3UKygXwg0CEW3Y=; b=N+DK1E+V5JhLJkFgF43NtKAGcoTuhEOQsQtPIQHLngQVl82tWIEavuPLwJL1GK/JW96/ U9XyWrlplluXtmeZvq1s4K/6khGpFI/fPXz94x4H44RCHSRogV8OjEysADlFHiFKDQsW qcbgBX9h+Bm1pn1HpBpQPgdW+D1vAQ+IiChdvCwSMAd0zLBofOl3HKE4qQqXA9nvqniN vCx9GTLVKYho8tb6UCgOLi6XypaiGBmwmG1CFF9m5Y1Y1j8/oIoGRBMNsSQAygj53ll0 i5r0lbaq6gITm4Zp6W1L8lR79SKO3syHMeSIiNnWoHpLHcB3RDQIBpjm/hXVaokyK3EQ 8g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 323wackemj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 08 Jul 2020 01:07:06 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06814GEP135666; Wed, 8 Jul 2020 01:05:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 3233py2mut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jul 2020 01:05:05 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 068154Wj017086; Wed, 8 Jul 2020 01:05:04 GMT Received: from dhcp-10-159-235-215.vpn.oracle.com (/10.159.235.215) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 07 Jul 2020 18:05:04 -0700 Subject: Re: [PATCH v4] IB/sa: Resolving use-after-free in ib_nl_send_msg To: Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Kaike Wan , Gerd Rausch , =?UTF-8?Q?H=c3=a5kon_Bugge?= , Srinivas Eeda , Rama Nichanamatlu , Doug Ledford , Leon Romanovsky References: <1592964789-14533-1-git-send-email-divya.indi@oracle.com> <20200702190738.GA759483@nvidia.com> From: Divya Indi Message-ID: Date: Tue, 7 Jul 2020 18:05:02 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200702190738.GA759483@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9675 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=11 adultscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007080002 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9675 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 cotscore=-2147483648 suspectscore=11 impostorscore=0 bulkscore=0 mlxscore=0 clxscore=1011 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2007080002 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks Jason. Appreciate your help and feedback for fixing this issue. Would it be possible to access the edited version of the patch? If yes, please share a pointer to the same. Thanks, Divya On 7/2/20 12:07 PM, Jason Gunthorpe wrote: > On Tue, Jun 23, 2020 at 07:13:09PM -0700, Divya Indi wrote: >> Commit 3ebd2fd0d011 ("IB/sa: Put netlink request into the request list before sending")' >> - >> 1. Adds the query to the request list before ib_nl_snd_msg. >> 2. Moves ib_nl_send_msg out of spinlock, hence safe to use gfp_mask as is. >> >> However, if there is a delay in sending out the request (For >> eg: Delay due to low memory situation) the timer to handle request timeout >> might kick in before the request is sent out to ibacm via netlink. >> ib_nl_request_timeout may release the query causing a use after free situation >> while accessing the query in ib_nl_send_msg. >> >> Call Trace for the above race: >> >> [] ? ib_pack+0x17b/0x240 [ib_core] >> [] ib_sa_path_rec_get+0x181/0x200 [ib_sa] >> [] rdma_resolve_route+0x3c0/0x8d0 [rdma_cm] >> [] ? cma_bind_port+0xa0/0xa0 [rdma_cm] >> [] ? rds_rdma_cm_event_handler_cmn+0x850/0x850 >> [rds_rdma] >> [] rds_rdma_cm_event_handler_cmn+0x22c/0x850 >> [rds_rdma] >> [] rds_rdma_cm_event_handler+0x10/0x20 [rds_rdma] >> [] addr_handler+0x9e/0x140 [rdma_cm] >> [] process_req+0x134/0x190 [ib_addr] >> [] process_one_work+0x169/0x4a0 >> [] worker_thread+0x5b/0x560 >> [] ? flush_delayed_work+0x50/0x50 >> [] kthread+0xcb/0xf0 >> [] ? __schedule+0x24a/0x810 >> [] ? __schedule+0x24a/0x810 >> [] ? kthread_create_on_node+0x180/0x180 >> [] ret_from_fork+0x47/0x90 >> [] ? kthread_create_on_node+0x180/0x180 >> .... >> RIP [] send_mad+0x33d/0x5d0 [ib_sa] >> >> To resolve the above issue - >> 1. Add the req to the request list only after the request has been sent out. >> 2. To handle the race where response comes in before adding request to >> the request list, send(rdma_nl_multicast) and add to list while holding the >> spinlock - request_lock. >> 3. Use non blocking memory allocation flags for rdma_nl_multicast since it is >> called while holding a spinlock. >> >> Fixes: 3ebd2fd0d011 ("IB/sa: Put netlink request into the request list >> before sending") >> >> Signed-off-by: Divya Indi >> --- >> v1: >> - Use flag IB_SA_NL_QUERY_SENT to prevent the use-after-free. >> >> v2: >> - Use atomic bit ops for setting and testing IB_SA_NL_QUERY_SENT. >> - Rewording and adding comments. >> >> v3: >> - Change approach and remove usage of IB_SA_NL_QUERY_SENT. >> - Add req to request list only after the request has been sent out. >> - Send and add to list while holding the spinlock (request_lock). >> - Overide gfp_mask and use GFP_NOWAIT for rdma_nl_multicast since we >> need non blocking memory allocation while holding spinlock. >> >> v4: >> - Formatting changes. >> - Use GFP_NOWAIT conditionally - Only when GFP_ATOMIC is not provided by caller. >> --- >> drivers/infiniband/core/sa_query.c | 41 ++++++++++++++++++++++---------------- >> 1 file changed, 24 insertions(+), 17 deletions(-) > I made a few edits, and applied to for-rc > > Thanks, > Jason