Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp961373lqh; Sun, 5 May 2024 09:21:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcvWDf1OOiExl0enuSaCEu+Y+i9wR5pF4VBj3Lo1n3ukMRWNLz117Jx6JhaYLvS+mBVM3GXjyPx41aNMdfjp6kY6afD0IneCRe7+0z8w== X-Google-Smtp-Source: AGHT+IGBXNRmsT60GVsVB9jXX8+JnWuoxLAr42hprxRVgcUKtoB5eBedQfLnUa8c3sI7Zkotwp5s X-Received: by 2002:a05:6a20:9f88:b0:1af:a4a5:a272 with SMTP id mm8-20020a056a209f8800b001afa4a5a272mr2750885pzb.9.1714926100242; Sun, 05 May 2024 09:21:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714926100; cv=pass; d=google.com; s=arc-20160816; b=yFHhwIvZcvUHHJsPvheF1/WiwfjD9UqH1unj1/iXeBGATvq9sDykhdPOhhmQ0tBPGC yeWowhvF64v/XLhpCTn2Lody4PXCzQSclF/eM9eXbEfg6+u3pZI9u/VScksCUSXSWQlZ iExKpCZeU9GzXWTn1kzWk2J8gvRuGR88qCAP+Z5tvYNeDeicqZ2QugeoBaAPPvDMpxdE X2kRH/dGWbwsfCMWCJwsNwTtDTGBVQ5zKQ2SGuPkInNYzJW8ZV+H+NcNOgiYGnTPYjOz y9g9otxe6cIiq6sTsWWWDkU5vkN/aJwo8KdylymBJgUWTz+yvuJhWA0ZmvmewuSf/eRY EQtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=f16PTek0Bmvx5v9zUadis064ktYQgiNdbOEhCsQmxFI=; fh=1SRkQcBggaUJ47BA1y87kdwDMw+TdnNUzUP7T3+dbes=; b=sArZjrO2sk9v4JGrEi9MEkt6pz1QTdsuVu6kRK7ldTWT6bZrOpLQviI+E50ieUPnmL fThc1OOVyJxC6nBgvFdJ0D+llXzWZaXScIy3CZSxWUstXnHnZOYMgOcwxwcmyqjDVU7d mhOdeN41JJPVYcQFKP+tm3INz6qlHxt4YOYYDCpBraMyNzppddtSpVarWeUiE5hJO/3q smTbDPPxs6+jVYsGHNI4QuJjrSZ4Fc+QQ1kmmcK5XMwqWGOrjxfh29K7MDgY57jBOcNg MprCLkVZnwnKF7ybEh4290jF0ian/UpWFGu2TVJ77Y5BRk7BnagrqOJmGvTMFSYAY4ji 3u5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ggpSEO1U; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-169056-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m9-20020a635809000000b0061e569da529si4063979pgb.588.2024.05.05.09.21.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 09:21:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169056-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=ggpSEO1U; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-169056-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E3D8AB20F81 for ; Sun, 5 May 2024 16:21:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CF413B7AC; Sun, 5 May 2024 16:21:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ggpSEO1U" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0EE21862C; Sun, 5 May 2024 16:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714926062; cv=none; b=WWb5Dohb2A3PnqPezSXuzhOzyNOY2FHX0lpprS+92mMRbCYkbZiTtfsVIEaH4ZLdFBrl4GOHq9bkxDt74dClTS2AjCnxyF5wDUjS9LQWdawNGDR7AJjVBpAhQHho4hmxXS6/Ht9llGSmvJgdKwu+ypoVNWQY/CVJu2lCdX9TSVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714926062; c=relaxed/simple; bh=fn1Y0Fvalw3p2xiNGMYhBKwqheSpAJk7ixl8Wk8aamo=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=X88XNBAIohm2rRvb5B3Y0nUFPAp4x9d+0vP4ygPku7h/XPUks9eWDirexnWa95ki40g+/MgN5gdoFca8O6QlMarLGq1e5ntNM/4YFwhsM3MJvxnOVG60bFl5SRoSyNQOZtI1yzycbB2y5TfR8xdG0uWDyypoycl6WAaVoOuj8x4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=ggpSEO1U; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 445GKsoH001827; Sun, 5 May 2024 16:20:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=f16PTek0Bmvx5v9zUadis064ktYQgiNdbOEhCsQmxFI=; b=gg pSEO1Ul1EY/ocAyYmnQOEI2R7EhbzsAypkD23jtGUaV4m151AfX6ayNiS8lprywO p4LDv0osm6nOW/XpvzlOPugEBepwEHUCNEzvsDHz2J/j54sFhJnmAyhxg4PCB9Bz 3M4b6AGZf0AQTscN1vz95rbrsdhOPkOcJxYtdQ7T67729CH8vU4bUETDaXe3xNY7 s9FHfHbixHskOWRGyclGnvKOhhx/sXnjUNUjChqqNT1GuGLUlZ6m7fhBf3cWTVtL kP8equFHH4sttbTRGeUqyAbljpK5wtYuoeC3iOPs1cKqz2V3bpVNhjpx0Vzqr/VA tmU7/SHCwQ89YNgZYPFw== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xwdsmsw2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 05 May 2024 16:20:53 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 445GKLO6028359 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 5 May 2024 16:20:21 GMT Received: from [10.216.45.66] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 5 May 2024 09:20:18 -0700 Message-ID: <8ca45837-cbed-28da-4a6f-0dcec8294f51@quicinc.com> Date: Sun, 5 May 2024 21:50:15 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] dmabuf: fix dmabuf file poll uaf issue Content-Language: en-US To: "T.J. Mercier" CC: =?UTF-8?Q?Christian_K=c3=b6nig?= , zhiguojiang , Sumit Semwal , , , , , References: <20240327022903.776-1-justinjiang@vivo.com> <5cf29162-a29d-4af7-b68e-aac5c862d20e@amd.com> <23375ba8-9558-4886-9c65-af9fe8e8e8b6@amd.com> <40ac02bb-efe2-4f52-a4f2-7b56d9b93d2c@amd.com> <4fedd80c-d5b6-4478-bfd3-02d1ee1a26e5@vivo.com> <2ebca2fd-9465-4e64-b3cc-ffb88ef87800@vivo.com> <289b9ad6-58a3-aa39-48ae-a244fe108354@quicinc.com> From: Charan Teja Kalla In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: u7R16SvhkSPx1h5AvS-rjsiofvcdveX_ X-Proofpoint-ORIG-GUID: u7R16SvhkSPx1h5AvS-rjsiofvcdveX_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-05_11,2024-05-03_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 mlxlogscore=853 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 phishscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405050073 Thanks T.J for the reply!! On 5/4/2024 4:43 AM, T.J. Mercier wrote: > It looks like a similar conclusion about epoll was reached at: > https://lore.kernel.org/all/a87d7ef8-2c59-4dc5-ba0a-b821d1effc72@amd.com/ > I am unaware of this discussion. Thanks... > I agree with Christian that it should not be possible for the file to > be freed while inside dma_buf_poll. Aside from causing problems in > dma_buf_poll, ep_item_poll itself would have issues dereferencing the > freed file pointer. > Not sure about my understanding: ep_item_poll() always call the ->poll() interface with a stable 'struct file' because of ep->mtx. This lock ensures that: a) If eventpoll_release_file() get the ep->mtx first, ->poll() corresponds to the epitem(target file) will never be called, because it is removed from the rdlist. b) If ep_send_events() get the ep->mtx() first, ->poll() will get called with a stable 'struct file', __but the refcount(->f_count) of a file can be zero__. I am saying that this is stable because the 'struct file' contents are still valid till we are in ->poll(). Can you/Christian help me with what I am missing here to say that ->poll() is receiving stale 'struct file*', please? And, If you are convinced with above, I think, It should have been the responsibility of ->poll() implementation to have taken refcount on a file that is going to be still valid even after ->poll() exits. Incase of dma_buf_poll() implementation, it took the refcount on a file that is not going to be valid once the dma_buf_poll() exits(because of mentioned race with the freeing of the 'struct file*'). So, in dma_buf_poll(), Should we be using atomic_long_inc_not_zero() based implementation to take the refcount on a file? Thanks, Charan