Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp187255rdb; Wed, 17 Jan 2024 23:52:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHG7PTuORhvIaY39nMIi+0knn5IiZFgxtwVFrehYEHs/65IhBNOanvPkcLf2vG+hSZXB88n X-Received: by 2002:a17:906:3d4:b0:a2e:7c89:5c96 with SMTP id c20-20020a17090603d400b00a2e7c895c96mr487374eja.65.1705564345567; Wed, 17 Jan 2024 23:52:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705564345; cv=pass; d=google.com; s=arc-20160816; b=mKYWAXPqYJImpj6Sr0hew/LUCfZ2unBC1qxmoq3k5PlR0bWpPBp5URn9M9hjTXRcBw eNsoefKhsYKO8MSA9MR5Hszgrekod0MAmi39xi606mK2Xzm9lorhLAqMuJPixKP7NpHr Ln4CtKyu2DwOPcM6N87up/IwRq0Kiv1hNdgLXk9ICj6lxufOGx9f/7XM/L178BA3ahER pLysYAwJKZI1rr5f3itIcImBr2qHvYWdQW3BE3mFGhtWzodCamHfXCl2egilNXRRPTub mANgL/hXzS3P9wOHLsU6Tu2aYzN1nQeprZRAS85nV8F5Ny7A+nJ1gI9U1K1zca9NFwPw pDTg== 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=6dIzuRjIhUom+9QBerzCRmVKHg1JCScoj3+KxXG1w7E=; fh=doppBI8VrTovtzlq/SiY5KtxG3Fhg5az8pQOnob6HPQ=; b=nWcUJ1ZkB8UeL7kp3/hFlh4Mj6paOeriahqLmiiS5cSdRFwm6a8a/iO6jWEO4jwfLf 2Kt6ablbLEWk6Ngny4agKJ+Rc6CpMmvr9FvschSPNHIUkVxbBHK+0ysEBawdLqxvKAcw BKAMLAuKpEfP48TRE/1mO8KSJUG5A28iZgu9MP67SD6g6ZRQnKTsiFY+JGLwu2M7aTSQ 8uNEOF4b7ORFX7lHgyEiSx0BTIJPjxAtfJ8darOcC8L/LF22SKwmLh+wPHgQLdgosQ+j ru3LkhzDPpu1ILXYwOjfvy7kQ+ACTHxZGy+iW3OM/fLqgSHfZG+9PA7J50XL31I4x6J7 uaXg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-29783-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29783-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j9-20020a170906410900b00a2e75cf6ec7si2263683ejk.130.2024.01.17.23.52.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:52:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29783-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-29783-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29783-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2CC691F233AC for ; Thu, 18 Jan 2024 07:52:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3638EC15B; Thu, 18 Jan 2024 07:52:12 +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 9C5B61170A; Thu, 18 Jan 2024 07:52:11 +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=1705564331; cv=none; b=OMrOj7D8NprDEeiQwV00wwXNbeGKOUZ743mDRUoqsbltx+alXEjcCVDtShMsmhRGnQF9mwCcCtHoaHEZ3M4FxFoAI3i8X19BjYGlFGWxewoxzObg1+yhcgN1pI1QEdItOLITEDkr96+VFS5iT4SqFLU4M8qB+KY/bwkvadak9oU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705564331; c=relaxed/simple; bh=2Fh9Tp3AdRnRiIVKXLJf0SM4987XhL95PCJwebTGEO8=; h=Received:Message-ID:Date:MIME-Version:User-Agent:Subject: Content-Language:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; b=MVJ31UwfQiaexQXq20iAogV5OMqYwwue31C/3hXOxZQcPmelDtZ0QjJnn7vObEz8vY+6cgApqoz34NXjPudWDGbJXFCWa08o4yM6HsZYuIh1wYRDIKWSTwB/89GkGCsXMz2qHmDA+KB10OTJNZbZErhNqnEVDA2qWxOSLH/7rKA= 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 72857C433C7; Thu, 18 Jan 2024 07:52:09 +0000 (UTC) Message-ID: Date: Thu, 18 Jan 2024 08:52:07 +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: "Zhao, Zijie" , "jani.nikula@intel.com" , "mchehab@kernel.org" , "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" Cc: "syzkaller@googlegroups.com" , "Zhang, Lingming" , "Yang, Chenyuan" References: From: Hans Verkuil In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 18/01/2024 05:25, Zhao, Zijie wrote: > Dear Developers, > > We hope this email finds you well. We took a deeper look at the first crash KASAN: slab-use-after-free Read in cec_queue_msg_fh. We believe the cause is that one thread took the lock of a `struct > cec_fh` but another thread freed it: > > One thread takes the lock of the `fh` of type `struct cec_fh`first (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L219); > Another thread frees this `fh` without checking if any other thread is holding the lock (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-api.c#L684); > Then KASAN is triggered when the first thread tries to access `fh->msgs` (https://elixir.bootlin.com/linux/v6.7-rc7/source/drivers/media/cec/core/cec-adap.c#L224). > > > While this particular reproducer seems harmless, we think the free might cause more problems when paired with threads running other functions that work on `fh`and then KASAN is disabled. We also think > the `struct cec_fh` (https://elixir.bootlin.com/linux/v6.7-rc7/source/include/media/cec.h#L90) is worth attention since it stores many function pointers (e.g. `fh->adap->ops` stores > https://elixir.bootlin.com/linux/v6.7-rc7/source/include/media/cec.h#L115 and `fh->adap->pin->ops` stores https://elixir.bootlin.com/linux/v6.7-rc7/source/include/media/cec-pin.h#L36). > > Could you please kindly take a look at the crashes as you have more expertise in them? I've been looking at these on and off whenever I have some time. I found two issues and am on the trail of a third. Once I have a patch for the third I was planning to post the patches and ask you to retest. Some of the issues you found might all relate to the same root cause (esp. the locking issue), so it would be great if you could help with that. Regards, Hans > > Thank you for your time! > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > *From:* Yang, Chenyuan > *Sent:* Wednesday, December 27, 2023 8:33 PM > *To:* linux-media@vger.kernel.org ; linux-kernel@vger.kernel.org > *Cc:* jani.nikula@intel.com ; hverkuil-cisco@xs4all.nl ; syzkaller@googlegroups.com ; mchehab@kernel.org > ; Zhao, Zijie ; Zhang, Lingming > *Subject:* [Linux Kernel Bugs] KASAN: slab-use-after-free Read in cec_queue_msg_fh and 4 other crashes in the cec device (`cec_ioctl`) >   > > 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. > >   > > Best, > > Chenyuan >