Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2075160pxb; Thu, 7 Oct 2021 23:38:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHpqJObhc+wks2KckyRkj1/eRbpUngubbUZ71vT23FZYqvqZD6mwg46pS0Blj1nFYb0Ukw X-Received: by 2002:a17:906:1405:: with SMTP id p5mr1930173ejc.197.1633675084844; Thu, 07 Oct 2021 23:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633675084; cv=none; d=google.com; s=arc-20160816; b=017wmXLYh/yYwk/677cW/O7CMH875o5J47MtE+sFx+ituKxCK2ZLcdlJbhB7GwZMXv WdSB9XCvGW/IO5lNvbg5lFWo1tYJchjdLIBotlY6Mst1ai0b7srhckwp+J5bmQjZx4gK H6iaSR2DqsFqqo2wUoeNclNB8hufXadZozHz3p05FrIj2Mfcz8VTiDP2tKvovX0X4ShU JY2bdc6xFY8PsDlimxibgh6lc/jyfKze1O70VXGQI5POf/c4S/gBQGnu2svM57zF9Y29 LZ53SDEo8gQWKyH+Ije074/doXp+MwKYdAlgulR4b35zhBKjL1+eF0Oi+ahJwhxVvkIn +33A== 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=0Apht4G8FwRx5QUZvXlGs47Zpiyo3ZBczks9sUYs2tc=; b=jEUGq1JCD+2BolBDwhGiPpBJLGW+KddYiEW5AM5nBXlaf9hAF1GI4YS8NUh4mLtgmj pCY4s8OiqPLJJ2UvpAo496A8oMVkZzFfpKkApO9q+Gtxz26J+O5cypBvOZjlCP6KS7mL 37r9lISso0tXBaPOnNGTY4RAc7YOTWN9I6SncerKmtBtrv321mrbPa9ouALd0ql3Po9Q qcIchjWT3wLd4yHZJx+pXlMpg6bry2GJfNk1wdoVZfP/ajYNIv5a8PUQ156LIM854EhE FEA4S1FXcs8WsvXg8iAVTHk4hfyf3Ph0KPNxGwlf+cz605EiRgn5Qf53UqYTs6kmnu8/ C+CQ== 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 gk1si3261247ejc.31.2021.10.07.23.37.41; Thu, 07 Oct 2021 23:38:04 -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 S231749AbhJHGhk (ORCPT + 99 others); Fri, 8 Oct 2021 02:37:40 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:47742 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229585AbhJHGhj (ORCPT ); Fri, 8 Oct 2021 02:37:39 -0400 X-UUID: eaea71e3e19d4ca6aede932f5f812b8e-20211008 X-UUID: eaea71e3e19d4ca6aede932f5f812b8e-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 49959066; Fri, 08 Oct 2021 14:35:42 +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 14:35:41 +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:35:40 +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 v2] dma-buf: acquire name lock before read/write dma_buf.name Date: Fri, 8 Oct 2021 14:37:22 +0800 Message-ID: <20211008063722.40181-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..9436483a9cfd 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(&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 +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(&buf_obj->name_lock); robj = buf_obj->resv; fence = dma_resv_excl_fence(robj); -- 2.17.1