Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2336001lqt; Mon, 22 Apr 2024 08:05:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+ACJ7Mbw8B2q+aU2D+1ztx4U+0LFRuHzmj+/IJv8mztBGxHVaGgOO974tWz1P8U/RCi0M0h6dLXm4qbdr+fX0wK+3E9zrbBMGdpvOLw== X-Google-Smtp-Source: AGHT+IHBJ9dge3A6MhNcj7qiCumbzZcb+fknoh2Z74cY+FfDc+7VDOwNmKxBPNTZYwQJ1XbdDu9Q X-Received: by 2002:a05:622a:38d:b0:437:bb65:3c2d with SMTP id j13-20020a05622a038d00b00437bb653c2dmr11322129qtx.0.1713798299924; Mon, 22 Apr 2024 08:04:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713798299; cv=pass; d=google.com; s=arc-20160816; b=ZfoW11necZSatFyyxjtQLAIjOtmq64bA5d0Y7R3xVnttwQdqSYYlcS7RZJAVupkgVd doO9UoYQcGxvQQrpfznLn6LhX5sJED75tPpNv6LXDczyXnlgRarXW69murPXJ0l79wpF hcqLOM0S6TgYulZg1XFfcIMEvVZcl4inbx4IdP/yBo1igr1jYINn87xnNDtLEJnq1ZZH OmWj/qfRv61j1QdzQdNRm705YHq8/C6xj9+nZfbcdFAPtP8MlitfATd6VEJG7A2X4oaR OUjfIHi4Jnhw2iZ7k+Z6VRL9L81FQ2tJYtdTtUh4/YcZ3LxOi0k8OhAUjr1wYK1f19Zx GOBg== 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=dSqURE/mfOWWW8bjY9CnmYk/pUVtC4HWXuY3Bdv86Ro=; fh=UeLN0hREXRw8KwKj3He1byeTh0ii8v9HHgvMGhH8UOk=; b=vFafv8crqbr0dDCsRrhDQTluyyWL2xmSUA/K61g5ZxD02I9/GFWrdUb5xxLbV18nYs WRpy5TzND0/eGWYs6jLtKmtVLgfh05umEGtyOtr3Vn2EbAT6KmDcOxlZjrKMd63u1faw MCFr/8K11hlgWHzPf8N06hhX0DEOKp3MgIP3y/UeA+16/QXxzjoBq8JM18twlCq5Baeo 6QQy/PZJZbMfT9RrqA1GeE8Q2qwsAPfjDRRWcmPWN46kVrzwD9i8UA4P/cVaVyiyjtcx KCWvOm6jvPRtGs/BE/GUyc/9UdFt2T16KlHw98Fk7heedC1T3v4H2Uwofrs8PLfZ2uSY TwxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-153599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153599-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 o6-20020a05622a138600b00434e4d50431si10867550qtk.184.2024.04.22.08.04.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 08:04:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153599-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-153599-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153599-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 970F01C21A41 for ; Mon, 22 Apr 2024 15:04:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81DFA15252F; Mon, 22 Apr 2024 15:04:48 +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 DC2FE15217D; Mon, 22 Apr 2024 15:04:47 +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=1713798287; cv=none; b=m5tRTjbGiS2SkahlpXi27334WHa1MwwkEiAkDBUdjAU9nIwz43aji0e3Mov7u0dXsQzIWqa//Z0Kg6ak+C3XQOkGMk1F7wHvEJAU2waJjYXgOFFEgmNg7V7uml8u+ETSmyvtTEk9Zg/R2tviRFh/WSmysBWmo4nzSXzWZexVqvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713798287; c=relaxed/simple; bh=5JG6CEJSC/3L87Wa3KY55TPd29wx7na1hq4gOaYVRe0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Bi6F135X01vki+TOUOSaxQBzeAtQUkUxK4s1d1cOf/r0TObHQqeB2Fkg5IVwg4h779Z5I5xCOuVlO0HAKyyRThQFJZUKSM66OudfWtq8J1vQUg4LAvTkBihzupI+XDnRgLCQgr+xOCNEsDBQjudsHxKo7is6wXG0HU70huce8hc= 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 B8FDFC113CC; Mon, 22 Apr 2024 15:04:45 +0000 (UTC) Message-ID: Date: Mon, 22 Apr 2024 17:04:43 +0200 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> <49a68c10-9549-4fd8-b929-d4c7a9c8debf@xs4all.nl> <7E36CBBD-F2AD-4D98-8D4E-F52E62C3E812@illinois.edu> From: Hans Verkuil In-Reply-To: <7E36CBBD-F2AD-4D98-8D4E-F52E62C3E812@illinois.edu> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Chenyuan, My apologies for the delay, I missed your email. On 26/02/2024 13:27, Yang, Chenyuan wrote: > Hi Hans, > > Thank you for your continued efforts in investigating this bug and implementing the new patch! > > Regarding the two warnings, they have been addressed by this new patch and are no longer reproducible. Additionally, I conducted a 48-hour fuzzing test on the CEC driver, which has successfully eliminated the previous hanging issue. > > One thing to note that the system will now log timeout events: > ``` > [ 2281.265385][ T2034] cec-vivid-001-vid-out0: transmit timed out > [ 2282.994510][ T2017] cec-vivid-000-vid-cap0: transmit timed out > [ 2283.063484][ T2050] cec-vivid-002-vid-out0: transmit timed out > [ 2283.073468][ T2065] cec-vivid-003-vid-cap0: transmit timed out > [ 2283.373518][ T2033] cec-vivid-001-vid-cap0: transmit timed out > [ 2285.113544][ T2018] cec-vivid-000-vid-out0: transmit timed out > [ 2285.193502][ T2050] cec-vivid-002-vid-out0: transmit timed out > [ 2285.193570][ T2065] cec-vivid-003-vid-cap0: transmit timed out > [ 2285.513570][ T2033] cec-vivid-001-vid-cap0: transmit timed out > ``` Is this happening all the time, or just once in a (long?) while? Regards, Hans > > Best, > Chenyuan > > From: Hans Verkuil > Date: Friday, February 23, 2024 at 8:44 AM > 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 > 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`) > 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; >