Received: by 2002:a05:7208:3188:b0:7e:5202:c8b4 with SMTP id r8csp888703rbd; Fri, 23 Feb 2024 06:45:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqLHVAXlxE2UEqv4XtiFBLUfivdY0HGY8b0n4v6CTQHK4eq8XQVrF29pe1niuJbANfwkGj/d2Pws/ukuP5AF53GAsm1/+H9tbKM5bbeg== X-Google-Smtp-Source: AGHT+IFKiL55MthCDgMWVS3Y4yV07UJslbiNI69oDBZ+DOGII0f2iEPNTAeKT8BZg5KuH5Nw84kw X-Received: by 2002:a05:620a:4588:b0:787:a692:9824 with SMTP id bp8-20020a05620a458800b00787a6929824mr14938qkb.9.1708699550759; Fri, 23 Feb 2024 06:45:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708699550; cv=pass; d=google.com; s=arc-20160816; b=IpefM8t+WuDjMXSI3ebuGedGl4m/r9RgW3Eu3dlfdjTx9nYXkUWYTObn7RbBn5RJg3 GCtpKIS6oteSM09Ab/tQCi6g13sv8cdEO/q0gAjbsbJppXHWs+qlp6uiXMaEROSetsFg j9Ialj5wbpoyVHJanMPpI4GLeC3F6JdUDGcHDwUZ4gYwOPsbjEzX5LA362VZagUIY+HL xA5ofV6UwaqnMSVNoLHbSULjvGXAr+b55LY4ArZLLRq5NzywvH8USFeu19gMfL/Kcy82 ZnF5oFrjegyMULqeOIF/5k/CMVDdXBrWo2WVwJ/36U9GjsrZg4uDkbTJjLFnMz3PH9JF gpsA== 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=eCnamr1l1E05VvGYdaIduJg6cfJwj3K1bmSuvjfjFxA=; fh=UeLN0hREXRw8KwKj3He1byeTh0ii8v9HHgvMGhH8UOk=; b=vctG8e/WccSZV2niHz5f7ZjEQnK9g5zOffNCczSVATW1wH9sMPXlj1pdiDwi0ukLrF xAvWLJUhp1L4+1oOpwGQrR0TMVYTy7tf7UD+q2zxjxuSAwwDLqikMZGKw3Tqp0jBYW5l VVz6reimd5rifl+XWwxPsm4ome6pHUAfE5mEVNDdw5n+lMVhM8quF91csX8cvevV09E0 VjlUO5zBgXD2ELIfySe3XDHz564BDmzBx0xRtJZVO6JQErLl+85KCzZo2hPZCsBGOy3i 8d8x3Sn0CqaKpjEL8mGTvILy2zFRCWyE4oP+5WSzdGoobjaWO2YQs3blD481ysY3V2Wy FrHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-78518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78518-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. [147.75.199.223]) by mx.google.com with ESMTPS id j15-20020a05620a146f00b007872b2bc37asi15261102qkl.293.2024.02.23.06.45.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:45:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-78518-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78518-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 3699F1C22D4F for ; Fri, 23 Feb 2024 14:45:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61C4381213; Fri, 23 Feb 2024 14:44:29 +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 C912514B815; Fri, 23 Feb 2024 14:44:28 +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=1708699468; cv=none; b=ew6bDsXEjXJ1138M4DYDqMhXCJUbxTbYO4CLGFAjMEZQj++zGNABhMTpxZnX/tSDNT+A1a/3cYpdnJbI0igecJIvOgzcbKsfjK6T7KeKSwpzr2Czw5vL+L93Wvav+7krcS2ZTokUx2Td0GA3S/h618wApgo7W/vTow2jZaaXan8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708699468; c=relaxed/simple; bh=RyvUCZi8Wj5AWG9UJJBgJ1vhks86ype6GuNjY56uF5s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SQQEXUyEDoS25kYCyaCopWDTU7fgdhbrWNwkZ3b5IzAlKQopfKsVwqgITFErqCBYvKX3Lw2Nmdqlghml2eUWuxACf9WYowBIEDMsbU47+5e32hs6JBE5rVb96etWPWAMjBusM5dpBdn6TtfGbh9ssOyRA6XXYZ+Vj+GMxxsLxFo= 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 01691C433C7; Fri, 23 Feb 2024 14:44:26 +0000 (UTC) Message-ID: <49a68c10-9549-4fd8-b929-d4c7a9c8debf@xs4all.nl> Date: Fri, 23 Feb 2024 15:44:25 +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: <526380BE-57AC-493D-A7B0-B8F0ECC0FE0A@illinois.edu> <2e5f1e92-7fad-4a74-b375-1e194ff08ce6@xs4all.nl> From: Hans Verkuil In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Chenyuan, Here is another patch for you to try. I think it is good for blocking CEC_ADAP_S_LOG_ADDRS ioctl calls, but if the filehandle is in non-blocking mode, I'm still not certain it is correct. But one issue at a time :-) Regards, Hans diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index 559a172ebc6c..a493cbce2456 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 */ @@ -1575,9 +1574,12 @@ static int cec_config_thread_func(void *arg) */ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) { - if (WARN_ON(adap->is_configuring || adap->is_configured)) + if (WARN_ON(adap->is_claiming_log_addrs || + adap->is_configuring || adap->is_configured)) return; + adap->is_claiming_log_addrs = true; + init_completion(&adap->config_completion); /* Ready to kick off the thread */ @@ -1592,6 +1594,7 @@ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) wait_for_completion(&adap->config_completion); mutex_lock(&adap->lock); } + adap->is_claiming_log_addrs = false; } /* diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index 67dc79ef1705..3ef915344304 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -178,7 +178,7 @@ static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh, CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU | CEC_LOG_ADDRS_FL_CDC_ONLY; mutex_lock(&adap->lock); - if (!adap->is_configuring && + if (!adap->is_claiming_log_addrs && !adap->is_configuring && (!log_addrs.num_log_addrs || !adap->is_configured) && !cec_is_busy(adap, fh)) { err = __cec_s_log_addrs(adap, &log_addrs, block); @@ -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); diff --git a/include/media/cec.h b/include/media/cec.h index 10c9cf6058b7..cc3fcd0496c3 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -258,6 +258,7 @@ struct cec_adapter { u16 phys_addr; bool needs_hpd; bool is_enabled; + bool is_claiming_log_addrs; bool is_configuring; bool must_reconfigure; bool is_configured;