Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1513520lqo; Sat, 18 May 2024 06:33:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJp1DC0a/Z4wMpr9Yl9l0wMv3xyJ2SikKpDHA1bkIxiytmqEF6ETFJXWdpn2+/vWIGZ6j8NxzV8cZZH9VE7pJUzhpQA2NkLWk5YmiqIg== X-Google-Smtp-Source: AGHT+IEdu5ivmt1MI6S5ZT8bMmTQiA8hd5qheZi8bq3F+RAb6kBSZfWXc4/M5bQCkWTGf/LZdaoi X-Received: by 2002:a17:906:3197:b0:a59:cf38:5339 with SMTP id a640c23a62f3a-a5a2d55a6e6mr1781200866b.6.1716039182736; Sat, 18 May 2024 06:33:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716039182; cv=pass; d=google.com; s=arc-20160816; b=VoIlvQdaXg9jxDDTO+3eaF6C24eRgq5f9F9gpGcOk/8e2u9PB0GzeplMz2PcVzYKIk KGwBQm2RtyM1/EUYMAGw2ZM9Gqv2XGISvtzQ9ewgVpCm0Un4A3ilDAbSe1xaDxRMedy9 PqngqM9RZDehU+gzZ7cwRLD/wyuFznHg4fCJTSFS8aCjPePVctU2cDJS6i6XII8pGUgR lKmbN4wSUzRnPl+oU3+9My0+6GTbF6qBbTl6dPG1n+MfA9FjC1wrH//2yxCbRx5of/C5 g0Y5BktK4d55R3pwB439dEVyopMArbd/uNMssPGzgorymXz5L2nhTURHERi0jYi/uXdp ka8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=cNL7WZI4Wjl8ae3AlsFkfNuoqI0yryDonK32mEDVuKo=; fh=FTMOYpnP11Cksqj4MzZtOdjfWROeJPpTM6tRf6vEli4=; b=og3pGZ8PwYI2ggC4lNYUQ7d3f5ctdj40LNW3/d3ccxF9BxpZaIF2qi+AVieKTd0cRW YVkIxXYGbMSgJFtZ99RfivobVJ92/qxTtQcjYE55Xn1PI1DeErRLmZPzKWHLXMQcSTal rJTDDP8yHI60aoCV9Jv35YAfjEHhmDsV8pcAk/eQi43OvGXkPynIKnbtJoicKSRAGmRD 3aPyqnfHsPVWrC6f4+leZd050pAXu/u2FEPBU9Cul9G5npVxnbKO9Vxt9pxHY8XZPmD4 crG1cRULguOQCH3dxuerWxCa+fUuVz8iEMxWH83VRHXQvC9cxjQL2bPnUAU4ObHN2h0H WqfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sina.com); spf=pass (google.com: domain of linux-kernel+bounces-182887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182887-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17946294si1117214066b.55.2024.05.18.06.33.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 May 2024 06:33:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sina.com); spf=pass (google.com: domain of linux-kernel+bounces-182887-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182887-linux.lists.archive=gmail.com@vger.kernel.org" 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 40E281F21771 for ; Sat, 18 May 2024 13:33:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2D6745027; Sat, 18 May 2024 13:32:55 +0000 (UTC) Received: from mail115-95.sinamail.sina.com.cn (mail115-95.sinamail.sina.com.cn [218.30.115.95]) (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 BBF2444C68 for ; Sat, 18 May 2024 13:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=218.30.115.95 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716039175; cv=none; b=r5mhXcdppxOek0aqkfTKW3NgHSAnFfwnwSlOGsysDaupHBlBJFGa38MGhYXv8lNVWwD+KB0bVqP/UdXQpNDI8wfUH+zaMxwR6BjbsypJ2IVvymU4Q/6phHWJQDOUYr9ygLY8on8k1vV2sB+ZAADMhCJJbhp8ZUXKq6EWRHsUkUg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716039175; c=relaxed/simple; bh=JdazwBK4bkajEq/wRvW8Nb0uRxQC6Npz7GCpLPQV1OQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ee5cbMvfpTsutod9n0n40ygE+XPGjBNUFI9OLEh2b0lvex3NC3tmuq6t1iC8aMd8VDmiDtFLa5wbO3s6T700qMD1dpFrbebezvHusPsnmncxonm0XqfJdIb3jI2UpfmKaNXUcerk1GbPH/Ls1hZzE/9uLiVayPGusHUxbL4RD1s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; arc=none smtp.client-ip=218.30.115.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([113.118.68.133]) by sina.com (172.16.235.24) with ESMTP id 6648ADFB000051C5; Sat, 18 May 2024 21:32:46 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 62476645089248 X-SMAIL-UIID: 6E5007454AB443D1B15672DC94C66522-20240518-213246-1 From: Hillf Danton To: syzbot Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] [v9fs?] KASAN: slab-use-after-free Read in p9_fid_destroy Date: Sat, 18 May 2024 21:32:34 +0800 Message-Id: <20240518133234.1786-1-hdanton@sina.com> In-Reply-To: <00000000000049897e0618a4b1ff@google.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Fri, 17 May 2024 04:31:28 -0700 > syzbot has found a reproducer for the following issue on: > > HEAD commit: ea5f6ad9ad96 Merge tag 'platform-drivers-x86-v6.10-1' of g.. > git tree: upstream > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11df3084980000 #syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ea5f6ad9ad96 --- x/net/9p/client.c +++ y/net/9p/client.c @@ -703,8 +703,6 @@ p9_client_rpc(struct p9_client *c, int8_ err = c->trans_mod->request(c, req); if (err < 0) { - /* write won't happen */ - p9_req_put(c, req); if (err != -ERESTARTSYS && err != -EFAULT) c->status = Disconnected; goto recalc_sigpending; @@ -879,15 +877,19 @@ static void p9_fid_destroy(struct p9_fid { struct p9_client *clnt; unsigned long flags; + bool empty; p9_debug(P9_DEBUG_FID, "fid %d\n", fid->fid); trace_9p_fid_ref(fid, P9_FID_REF_DESTROY); clnt = fid->clnt; spin_lock_irqsave(&clnt->lock, flags); idr_remove(&clnt->fids, fid->fid); + empty = idr_is_empty(&clnt->fids) && clnt->status == Hung + 1; spin_unlock_irqrestore(&clnt->lock, flags); kfree(fid->rdir); kfree(fid); + if (empty) + kfree(clnt); } /* We also need to export tracepoint symbols for tracepoint_enabled() */ @@ -1057,6 +1059,8 @@ EXPORT_SYMBOL(p9_client_create); void p9_client_destroy(struct p9_client *clnt) { struct p9_fid *fid; + unsigned long flags; + bool empty; int id; p9_debug(P9_DEBUG_MUX, "clnt %p\n", clnt); @@ -1068,13 +1072,18 @@ void p9_client_destroy(struct p9_client idr_for_each_entry(&clnt->fids, fid, id) { pr_info("Found fid %d not clunked\n", fid->fid); - p9_fid_destroy(fid); } p9_tag_cleanup(clnt); kmem_cache_destroy(clnt->fcall_cache); - kfree(clnt); + spin_lock_irqsave(&clnt->lock, flags); + clnt->status = Hung + 1; + empty = idr_is_empty(&clnt->fids); + spin_unlock_irqrestore(&clnt->lock, flags); + + if (empty) + kfree(clnt); } EXPORT_SYMBOL(p9_client_destroy); --