Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10459775rwp; Thu, 20 Jul 2023 22:40:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGWavYkmt8wO+wRc/ePIrsZI47oiPJbsctoIBMxgtDg3qzPeUE7GUptAJOqnVs3YRM6fakW X-Received: by 2002:a05:6808:23d0:b0:39c:93ba:cb92 with SMTP id bq16-20020a05680823d000b0039c93bacb92mr1451332oib.8.1689918049399; Thu, 20 Jul 2023 22:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689918049; cv=none; d=google.com; s=arc-20160816; b=DLGpQ3AxPmIGh+L2idbCPVtk743F9XnvyIHSvZVYmpynsfTJhBIc/u3W1bFaW4dWJ9 dL16oMZK2kzNX+hROEG5FSslQogfWtc5MPVHuZMpvJYk1hj1bDd1lJqNfv0veXp7I5F5 AoLBd4uCI1175vPQtQ+UB+PVemq+zVK9xWGyKHGuF248KPurk2yHrb3h8CZxL5whUx3/ QY1lqNFPqSHkxBqZIndhfARDnzH1wODGaws/jYJZec523lSqUGmUGr+9OILV6ubp1a+v 6c63TMyf8oVjwSf9RqELYpGgJJ4uYeJUd4DKKMbxC3/Rfj+iRUsMk9IeeDaZkp6zjcQ0 ah0Q== 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 :dkim-signature; bh=is4yfTDpwWO2AAZZFAWxZyiVy0fv219MzD7n0YO+Wyw=; fh=KyhcizW2aFV79SSyKWKL1fwR7c71MYm5M4xdBhPEb2M=; b=UrulbaBn6ZsTUqf5ct+YAbT2bJ1PCLc0i5m1aC6yq4quMofXv9b4gm93WQEOaCaXFN W0j4ulVOkAIU+XFkeVzDj28zP+NV8C+7ao5QiruwGBh54j1e1HfjtGy1YgfEBgnDq19J LE/ucblYnCQ9GvJ8pGIfsq6uPEX2syU1ZF6cgbUMH5eSRIZsoFNJFhZnwd4UGgjeRHW4 kgluOzRQcdKYFemmrnOpKANSNutuy9gCRPSkCc/lZS17AREMwnUApz9xeRRNaLILfzdM Dv541rQA2cm5ZTbZEfMyAWdF7qp4fTOJj5oxlzJfbOGZ4rbQl6JpAla1HYEzNXhChSY9 cdQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pYqFNkQR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u186-20020a6379c3000000b00553854417e2si2074950pgc.244.2023.07.20.22.40.25; Thu, 20 Jul 2023 22:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=pYqFNkQR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjGUFT3 (ORCPT + 99 others); Fri, 21 Jul 2023 01:19:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjGUFT1 (ORCPT ); Fri, 21 Jul 2023 01:19:27 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E7181BFC; Thu, 20 Jul 2023 22:19:22 -0700 (PDT) X-UUID: 2444c6a6278611ee9cb5633481061a41-20230721 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=is4yfTDpwWO2AAZZFAWxZyiVy0fv219MzD7n0YO+Wyw=; b=pYqFNkQRM++T8rSoOzC489IEVneaHhk4KB2F/G741TFvk01t87jX+eQEQBeOfesvr/UGnhQQhklzqcxSf22M6TH16CUjvADdult5E/M6nFw7ucvbj8KgNHXDRxMFjfZww2zQCn0WViBw8br/hoA7mSelfr/t55/KlKgAXlRSa+E=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.28,REQID:9a6ebabb-4a33-4a61-9742-dd8f956a1fa4,IP:0,U RL:0,TC:0,Content:-20,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-20 X-CID-META: VersionHash:176cd25,CLOUDID:c18cea8e-7caa-48c2-8dbb-206f0389473c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:1,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO, DKR:0,DKP:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2444c6a6278611ee9cb5633481061a41-20230721 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1701829401; Fri, 21 Jul 2023 13:19:18 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 21 Jul 2023 13:19:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 21 Jul 2023 13:19:16 +0800 From: Will Shiu To: Jeff Layton , Chuck Lever , Alexander Viro , Christian Brauner , Matthias Brugger , AngeloGioacchino Del Regno , , , , CC: Will Shiu Subject: [PATCH] Fix BUG: KASAN: use-after-free in trace_event_raw_event_filelock_lock Date: Fri, 21 Jul 2023 13:19:04 +0800 Message-ID: <20230721051904.9317-1-Will.Shiu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As following backtrace, the struct file_lock request , in posix_lock_inode is free before ftrace function using. Replace the ftrace function ahead free flow could fix the use-after-free issue. [name:report&]=============================================== BUG:KASAN: use-after-free in trace_event_raw_event_filelock_lock+0x80/0x12c [name:report&]Read at addr f6ffff8025622620 by task NativeThread/16753 [name:report_hw_tags&]Pointer tag: [f6], memory tag: [fe] [name:report&] BT: Hardware name: MT6897 (DT) Call trace: dump_backtrace+0xf8/0x148 show_stack+0x18/0x24 dump_stack_lvl+0x60/0x7c print_report+0x2c8/0xa08 kasan_report+0xb0/0x120 __do_kernel_fault+0xc8/0x248 do_bad_area+0x30/0xdc do_tag_check_fault+0x1c/0x30 do_mem_abort+0x58/0xbc el1_abort+0x3c/0x5c el1h_64_sync_handler+0x54/0x90 el1h_64_sync+0x68/0x6c trace_event_raw_event_filelock_lock+0x80/0x12c posix_lock_inode+0xd0c/0xd60 do_lock_file_wait+0xb8/0x190 fcntl_setlk+0x2d8/0x440 ... [name:report&] [name:report&]Allocated by task 16752: ... slab_post_alloc_hook+0x74/0x340 kmem_cache_alloc+0x1b0/0x2f0 posix_lock_inode+0xb0/0xd60 ... [name:report&] [name:report&]Freed by task 16752: ... kmem_cache_free+0x274/0x5b0 locks_dispose_list+0x3c/0x148 posix_lock_inode+0xc40/0xd60 do_lock_file_wait+0xb8/0x190 fcntl_setlk+0x2d8/0x440 do_fcntl+0x150/0xc18 ... Signed-off-by: Will Shiu --- fs/locks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/locks.c b/fs/locks.c index df8b26a42524..a552bdb6badc 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1301,6 +1301,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, out: spin_unlock(&ctx->flc_lock); percpu_up_read(&file_rwsem); + trace_posix_lock_inode(inode, request, error); /* * Free any unused locks. */ @@ -1309,7 +1310,6 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, if (new_fl2) locks_free_lock(new_fl2); locks_dispose_list(&dispose); - trace_posix_lock_inode(inode, request, error); return error; } -- 2.18.0