Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2069375pxb; Thu, 7 Oct 2021 23:28:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd3Cp1/5eM6orX36hEMtBgYZ5txZZy6K+Xr2dizXoFg15rwVUHnNwXeLfI8nib3IoCdfbL X-Received: by 2002:a62:ce01:0:b0:44c:569c:5c3e with SMTP id y1-20020a62ce01000000b0044c569c5c3emr8402933pfg.77.1633674504967; Thu, 07 Oct 2021 23:28:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633674504; cv=none; d=google.com; s=arc-20160816; b=lRvI/zTxW0/H/O3dKLSlS76TmL5/fQKh58n1K8v89rEcprpssy9QvSi+hzVhh4SpVN uC7Up6iPae/Im0d3SCpEfh4Pbx2d0/9hRfbAK85QiMKM2QArIcpaYoYvI57+nbgYbeTh 6ThjnM7bkuCpBCFRpZiGED+OToWwtWFhjMNr8IdoZsArP6MOxA4y9ya5q3CB7nDg3bEj B5clH2VkT/JI/5t3UpadYTBRPrmTX2xccf2AG47JQpgz0XajnU0NucjS0WuhQ3uYHLN2 7yWprAV5bv9St5JCNNNsdj4uV+N8pgei/+fkSmCMW2bOG1drRaaONhrmrN5ZWtv8JjOi knDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=r1vryadvh2SvMrrNjCrgCx6PH91Ta6I7drLR6DZwbGU=; b=RZg6ljEHrEg1L3RjpcgonYS0vVgA6YSqf0gChvivBEYYPp6lgY9RBCw3drigSoMECc KAO/3sUFE/+GkIchrtI0eDt1ab4uTMmopQY46d0in0TV+Lpv1jehhHWnEQBo6CS4yiUt K7/CL3jZSoO148yvVoCLcw/iuJuDgXML2tsWW3fAtY6XZLNT+K0FG4LN3F8vSpELZbL1 iFq4K5Ecss2WrwfPCrJyIM2Nr7CHIxjVENpjAkAah9fOCRN+GnD6+NHM/fb7m3e+b3hI LSmEKw9rlH6f4CmiJGkBj0frOiJgqoh4lRbhX15wKWjcVBWNofYy1oqtiKp5f2m/J7EI VVmQ== 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 f14si4121088pfc.294.2021.10.07.23.28.12; Thu, 07 Oct 2021 23:28:24 -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 S231354AbhJHG3T (ORCPT + 99 others); Fri, 8 Oct 2021 02:29:19 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:33968 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229664AbhJHG3S (ORCPT ); Fri, 8 Oct 2021 02:29:18 -0400 X-UUID: 7b259ceebea74b16a99be15b1f92cd6c-20211008 X-UUID: 7b259ceebea74b16a99be15b1f92cd6c-20211008 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 291282554; Fri, 08 Oct 2021 14:27:20 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Fri, 8 Oct 2021 14:27:19 +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 14:27:18 +0800 From: To: Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Matthias Brugger , "open list:DMA BUFFER SHARING FRAMEWORK" , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" CC: , Guangming Cao Subject: [PATCH] dma-buf: acquire name lock before read/write dma_buf.name Date: Fri, 8 Oct 2021 14:29:03 +0800 Message-ID: <20211008062903.39731-1-guangming.cao@mediatek.com> X-Mailer: git-send-email 2.17.1 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 511fe0d217a0..aebb51b3ff52 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -80,7 +80,9 @@ static void dma_buf_release(struct dentry *dentry) dma_resv_fini(dmabuf->resv); module_put(dmabuf->owner); + spin_lock(&dmabuf->name_lock); kfree(dmabuf->name); + spin_unlock(&dmabuf->name_lock); kfree(dmabuf); } @@ -1372,6 +1374,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) if (ret) goto error_unlock; + + spin_lock(&dmabuf->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 +1383,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(&dmabuf->name_lock); robj = buf_obj->resv; fence = dma_resv_excl_fence(robj); -- 2.17.1