Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2118640pxb; Fri, 8 Oct 2021 00:54:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybTQkvXgLmbPQjdaj1fkaEAhoKufoUDJdLZX65kINAsYSGUNP6kOwjPL4io+uxDs3UsEMR X-Received: by 2002:a17:90a:1d6:: with SMTP id 22mr10068948pjd.39.1633679658748; Fri, 08 Oct 2021 00:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633679658; cv=none; d=google.com; s=arc-20160816; b=tpJWzL4T9iBUhGf71p9Tf7IS9OAzIhMg7rhrM2/bPKWQXeCTgfUYXwIacl9qvnxUZG ry6yhRUPVjz+2OScAMTB1Mss7nlybdUZ1/hAOP8ryqTD6eLQQDPjdrj9lW4aZsWs3g/r VchyNJEmwUOM/Bu8ozaaoL8Bmag5ApWIfUCxf+QD865jkt75jn31pZ38rrCfAIUgYDCl R0VtmA2dM45cabkfaxIJvTtlRx1NQNktCPSnUYgQdgD6/SYFNDRum95ygtSoHFr1G3nv MC+Vd17SO9fCXl62S1KyKwNgg88ad9smSwRpcMdeGl19gAnVPnk9fEPkHVdk/tC6nS9p dF6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=jqQzVpFclQ/nR1tcBwcQaV33VDxIyAlKhLjDzXIeHwA=; b=kqRwPlAZAd0vL2r59hQL6xQwjtSQRLohxqbpBsMmoa4hp1khmC/O3RbnCGm0HYtOc6 5KhGu/YIl4U2/f77W4/zHiVCVVLEVr1Nt7DZTz2QrAJbe6ugR4OBfChSr2vXoh1sNa+D Me2hCY4D9Yd15zdAjP/B2E80nGLIt2WFZCEEeCSeHukEcw4KalBwIBvWpG+p6cHoxxKa Gcm0osowNYLN8BCm4hkAVEhuGyGSmaCDNs+k8KL1uiJG6iYWDE71L/zogbHsK3d/Lb2C RgoW5NAMQIudQU+y8i1GnE0NqUsdfSd9f6klBEbnf2cgQ+wjtITOyENMyD2pXDYmezxG b4Nw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s8si2121100plr.51.2021.10.08.00.54.06; Fri, 08 Oct 2021 00:54:18 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232252AbhJHHyf (ORCPT + 99 others); Fri, 8 Oct 2021 03:54:35 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:37258 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229828AbhJHHye (ORCPT ); Fri, 8 Oct 2021 03:54:34 -0400 X-UUID: 5a6ce0d2cded4eea83ac7c5040e034c2-20211008 X-UUID: 5a6ce0d2cded4eea83ac7c5040e034c2-20211008 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 639703647; Fri, 08 Oct 2021 15:52:36 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Fri, 8 Oct 2021 15:52:36 +0800 Received: from mszswglt01.gcn.mediatek.inc (10.16.20.20) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 8 Oct 2021 15:52:35 +0800 From: To: CC: , , , , , , , , , , Guangming Cao Subject: [PATCH v2] dma-buf: acquire name lock before read/write dma_buf.name Date: Fri, 8 Oct 2021 15:54:20 +0800 Message-ID: <20211008075420.42874-1-guangming.cao@mediatek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <5b7cdb6c-45f2-6b31-bfdd-5cc68a2fda5e@amd.com> References: <5b7cdb6c-45f2-6b31-bfdd-5cc68a2fda5e@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guangming Cao Because dma-buf.name can be freed in func: "dma_buf_set_name", so, we need to acquire lock first before we read/write dma_buf.name to prevent Use After Free(UAF) issue. Signed-off-by: Guangming Cao --- drivers/dma-buf/dma-buf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 511fe0d217a0..a7f6fd13a635 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1372,6 +1372,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) if (ret) goto error_unlock; + + spin_lock(&buf_obj->name_lock); seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\t%08lu\t%s\n", buf_obj->size, buf_obj->file->f_flags, buf_obj->file->f_mode, @@ -1379,6 +1381,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->exp_name, file_inode(buf_obj->file)->i_ino, buf_obj->name ?: ""); + spin_unlock(&buf_obj->name_lock); robj = buf_obj->resv; fence = dma_resv_excl_fence(robj); -- 2.17.1