Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp852846rdb; Fri, 19 Jan 2024 00:17:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHq49GR/itG2eB6vCXhYE6bY4iMAJpQBLYma5GDyaOq/dPBU7i+FiyqPMUMBZcks92bZLan X-Received: by 2002:a05:622a:1103:b0:42a:673:8ae6 with SMTP id e3-20020a05622a110300b0042a06738ae6mr2045790qty.5.1705652261947; Fri, 19 Jan 2024 00:17:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705652261; cv=pass; d=google.com; s=arc-20160816; b=NwfjdcSCPiYNOM/ATWt38p/HCGsCKVp8XIafPavGY+Yvgr4I3RHGfsNNnbgUTC/mqL t1VIU2s5ZRWUZiYIl6UoUTsFD0gTQ+7Jnqju1P6h3PmCViVWngmDuQch3DFsrUnxF5qz XDWRqHZ/9EmpyJk7Ojf8mjuM3ia54Q2KPgSHeucbVJ+HAv5RbAtV0YqW3CRcAEqDNUAd D+sH3QmdZBnoqjqVmF7P88sPxNBQHKBdEGPn4BAFvq6T51VTn0NdwMfOsLb5cwJ+NjZh N6Eh8YvhOh+3ii1dF3IXYtfCgtVp5dhayPeG7oXb76W5Z1tuWOpAZSKUM0J7r1K5kH9q sIhA== 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; bh=L9pbdXMNLKBhX9CFnl/gWhWPeSuZeoqwVfIkq7+Fv2s=; fh=UeLN0hREXRw8KwKj3He1byeTh0ii8v9HHgvMGhH8UOk=; b=ZKPAc1xVO82VlxbSUcZR9KBeGnkQPqoOLGtnjuF/yXXrBBbYMWQDSDPeKhEATASZrM yai6D2kT09wt4C1am/Q/Lt6p4Ub/cPHfIIg8zuqNrt9tjejCs4ecnJjPa39Pc84DYxyh Cp68ADol0isG7/D59zV1cMZwuJWA45WVIShnmxu1IEXS2bTbGuVV4VYZ952nvAoOqGSn PbbrKq/SybqCAxLFttsVTOn/d6flTeZ07i+dM1quce5ENuISbDNVObH2WgZLxsr3OQX8 LhOH+HQRi5fssPIoNsDKmfIFUFNIeXD0CdyiJdXEz+o8L9OIx7qzMH1JICP6pp7j90zg sZ/g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-30887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30887-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u14-20020ac858ce000000b0042a1e75c7b2si2541366qta.196.2024.01.19.00.17.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:17:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-30887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30887-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B331C1C22DA8 for ; Fri, 19 Jan 2024 08:17:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C54C24B34; Fri, 19 Jan 2024 08:17:22 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C840AD50F; Fri, 19 Jan 2024 08:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705652241; cv=none; b=olh6BH2QsLQsMpQhZXsDajSt2DsR59T5Wh0BeDGeONwg7I/cGgguh9BBmKV0zzSP2AeMlwLTmj/nxg11WPpW+cj0NFd+pmQIPBBOBHsJPutbwFMmtn01BlZfXt9wUDsFO6G9eSKWBLDVOFYw3n3m7/4RyMI3F7ztlLCsO5X6hkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705652241; c=relaxed/simple; bh=fK4VruREjGzv4G2JJRe3w7i5qBgYFCIiHSzEs1R5aUo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OETkj8136Fm82jnm3amm0U/FDVCYenIePtbrW3wMDb2ZJphDtyxUZP4y8hfsFIRYFfucq/M/Qwdp0l6QryaEmH46G2G6YEHUuwkkLOy+DOiO+iVR5LtArPJpDbSx0cx17mrnSrPp2COfDeMQzpuKhyA59ryw4NuHppDFisNipMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9940EC433F1; Fri, 19 Jan 2024 08:17:19 +0000 (UTC) Message-ID: Date: Fri, 19 Jan 2024 09:17:17 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Linux Kernel Bugs] KASAN: slab-use-after-free Read in cec_queue_msg_fh and 4 other crashes in the cec device (`cec_ioctl`) Content-Language: en-US, nl To: "Yang, Chenyuan" , "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: "jani.nikula@intel.com" , "syzkaller@googlegroups.com" , "mchehab@kernel.org" , "Zhao, Zijie" , "Zhang, Lingming" References: From: Hans Verkuil In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Chenyuan, On 28/12/2023 03:33, Yang, Chenyuan wrote: > Hello, > >   > > We encountered 5 different crashes in the cec device by using our generated syscall specification for it, here are the descriptions of these 5 crashes and the related files are attached: > > 1. KASAN: slab-use-after-free Read in cec_queue_msg_fh (Reproducible) > > 2. WARNING: ODEBUG bug in cec_transmit_msg_fh > > 3. WARNING in cec_data_cancel > > 4. INFO: task hung in cec_claim_log_addrs (Reproducible) > > 5. general protection fault in cec_transmit_done_ts > >   > > For “KASAN: slab-use-after-free Read in cec_queue_msg_fh”, we attached a syzkaller program to reproduce it. This crash is caused by ` list_add_tail(&entry->list, &fh->msgs);` > (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L224 ), which reads a > variable freed by `kfree(fh);` (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-api.c#L684 > ). The reproducible program is a Syzkaller program, which can be executed following this document: > https://github.com/google/syzkaller/blob/master/docs/executing_syzkaller_programs.md . > >   > > For “WARNING: ODEBUG bug in cec_transmit_msg_fh”, unfortunately we failed to reproduce it but we indeed trigger this crash almost every time when we fuzz the cec device only. We attached the report > and log for this bug. It tries freeing an active object by using `kfree(data);` (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L930 > ). > >   > > For “WARNING in cec_data_cancel”, it is an internal warning used in cec_data_cancel (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L365 > ), which checks whether the transmit is the current or pending. Unfortunately, we also don't have the > reproducible program for this bug, but we attach the report and log. > >   > > For “INFO: task hung in cec_claim_log_addrs”, the kernel hangs when the cec device ` wait_for_completion(&adap->config_completion);` > (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L1579 ). We have a > reproducible C program for this. > >   > > For “general protection fault in cec_transmit_done_ts”, the cec device tries derefencing a non-canonical address 0xdffffc00000000e0: 0000 [#1], which is related to the invocation ` > cec_transmit_attempt_done_ts ` (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L697 > ). It seems that the address of cec_adapter is totally wrong. We do not have a reproducible program for this > bug, but the log and report for it are attached. > >   > > If you have any questions or require more information, please feel free to contact us. Can you retest with the patch below? I'm fairly certain this will fix issues 1 and 2. I suspect at least some of the others are related to 1 & 2, but since I could never get the reproducers working reliably, I had a hard time determining if there are more bugs or if this patch resolves everything. Your help testing this patch will be appreciated! Regards, Hans Signed-off-by: Hans Verkuil --- drivers/media/cec/core/cec-adap.c | 3 +-- drivers/media/cec/core/cec-api.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index 5741adf09a2e..079c3b142d91 100644 --- a/drivers/media/cec/core/cec-adap.c +++ b/drivers/media/cec/core/cec-adap.c @@ -936,8 +936,7 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg, */ mutex_unlock(&adap->lock); wait_for_completion_killable(&data->c); - if (!data->completed) - cancel_delayed_work_sync(&data->work); + cancel_delayed_work_sync(&data->work); mutex_lock(&adap->lock); /* Cancel the transmit if it was interrupted */ diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index 67dc79ef1705..d64bb716f9c6 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -664,6 +664,8 @@ static int cec_release(struct inode *inode, struct file *filp) list_del_init(&data->xfer_list); } mutex_unlock(&adap->lock); + + mutex_lock(&fh->lock); while (!list_empty(&fh->msgs)) { struct cec_msg_entry *entry = list_first_entry(&fh->msgs, struct cec_msg_entry, list); @@ -681,6 +683,7 @@ static int cec_release(struct inode *inode, struct file *filp) kfree(entry); } } + mutex_unlock(&fh->lock); kfree(fh); cec_put_device(devnode); -- 2.42.0