From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20A303F0751 for ; Fri, 8 May 2026 14:25:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778250309; cv=none; b=EU5r2Duu4xybhqqehFU+OsyH1lGekvnZlaDskMVanA3f+S4ZJYBzQPtq1qht2zqo1tc49EfYszi0annk/l3kEnAXJ73uYe+p6M23C9tPlptSTvHtDv9sUZJR2kWA8Lj1lHgUxgYzd8U5Sgb11riYzdWKTIzgL+9CfYI7eePuLyM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778250309; c=relaxed/simple; bh=aAVkz69vD33yhtOgiJeMkQeov5eMMi7o2uoGq2OqIsw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Rk3JJHO3n/mwuFQd/9I7w1RdYNSh11lmH1A5kAfefFGJFBCwTy9FD2wATN2i0iPwhzma4kcpbrFRYmpfd0u7hU62y5tnr6AoH9WqZ5g7TJ+f+wbOxwzP14jxWyL2KzsOVldm9WdRTw7yOGcRZ4OTR/Zoo7JYQcdKnT3oCuGOKb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uxo9Imsk; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uxo9Imsk" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b4654f9bb6so23348085ad.2 for ; Fri, 08 May 2026 07:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778250307; x=1778855107; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WH26AvtCBPGbA9WUcHtqgl/A+uk1Xhz5GMhmaOiRbZA=; b=uxo9Imsk7mdYPtbS32DX/TR2B6mfy0fOtuQA1LkrsT+vn4w3Gq8u56Ios52bO9h133 8gO6Xg5eDfsyC6Nl8njvPcITvdBgnjTEqXrCik8eIpkKEbDfnhCekn916iJkbpl/ooSB aZb2kCSwlD6ZePQamV9ZYBORHNIoJ23F8EmEMp5qzCGI+ZQ9ePNOIvkf0T0K8U4DpwoV ++x+4peS910uSH/dpCvhVNOhSUIbqemjSp+/ItWHTEfFiWKBvVtyL+XZNbXpiNJ7mT8u AwOxtUeUxtrBzbvLTZ5tsOJDcKOp9K1CIr5Nl01V307X38cHGLKTzC+u8j/71SJG0IdG ggIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778250307; x=1778855107; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WH26AvtCBPGbA9WUcHtqgl/A+uk1Xhz5GMhmaOiRbZA=; b=Sm7D/C+B/nI0e/01DzhffTjHxrvBysv/xf44zqPEN73ly4EGz7qV+CHA0Bpypz+S50 25zCzlduvjnUnj3AsdZeC5Nq9hFY6LBDQqqtRjWC9lxy03OEJY5O19TQ1ZsA0yO9ATbe +pzrAO03tBZgy4Zzrq0Sv7GMywXRCSe7RkxR/pTnT6lS1i92yrD09E71l0vMVlxj8c2L Ay3oo3cXvq0B2pgvN4VMab1x3hIPAKDVKinVZcZSjpJWqUsxB5T4I6GpcMdpN3rEaqnG PQ2ewQQ16bux1rzzg8ESXiKdUIgimudpJKrv+Zs3oBrliQ7srmz3DG6Ygh2XktzJyEd0 vbrg== X-Forwarded-Encrypted: i=1; AFNElJ/Esg3f3jHU8Owb4Um64lqCsoLS0yjCvA8QNC2XejBBRZFRR7UJfctMqYve0CaezBdxI87ZrwdUDHlBhEg=@vger.kernel.org X-Gm-Message-State: AOJu0YyWgHdkjRZn55yYa28fbxfLqsabqQnusKT8hKLqvDKavp0Nlpgz L+xXOjlgSRHmmYHLC9wicu5gq+GeIttswapS6RxRDXd4OHCA7JcheVqgh48NyQjrqr4BynE7GcO gdjc7fQ== X-Received: from plox6.prod.google.com ([2002:a17:902:8ec6:b0:2b0:b12e:1b07]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3c2b:b0:2b4:689a:e411 with SMTP id d9443c01a7336-2ba794b80ddmr138393945ad.22.1778250307161; Fri, 08 May 2026 07:25:07 -0700 (PDT) Date: Fri, 8 May 2026 07:25:06 -0700 In-Reply-To: <41da263a-ca8e-4041-8214-b6b9f80edebb@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <67a2f20537354628bcb835586a7c6255@huawei.com> <41da263a-ca8e-4041-8214-b6b9f80edebb@huawei.com> Message-ID: Subject: Re: [BUG REPORT] USE_AFTER_FREE in complete_emulated_mmio found by KASAN/Syzkaller fuzz test (v5.10.0) From: Sean Christopherson To: Xinyu Zheng Cc: Zhangjiaji , Paolo Bonzini , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Wangqinxiao (Tom)" , zhangyashu , "wangyanan (Y)" , zouyipeng Content-Type: text/plain; charset="us-ascii" On Fri, May 08, 2026, Xinyu Zheng wrote: > On 2/19/2026 4:56 AM, Sean Christopherson wrote: > > On Tue, Feb 10, 2026, Sean Christopherson wrote: > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > index 2c7d76262898..0bb2a34fb93d 100644 > > --- a/include/linux/kvm_host.h > > +++ b/include/linux/kvm_host.h > > @@ -320,7 +320,8 @@ static inline bool kvm_vcpu_can_poll(ktime_t cur, ktime_t stop) > > struct kvm_mmio_fragment { > > gpa_t gpa; > > void *data; > > - unsigned len; > > + u64 val; > > Hi, Jiayi and Sean, > > Since I met a KABI consistence break problem from this change, I am finding > a way to avoid add including kvm_mmio_fragment.val. I assume you're looking for a solution for a private/proprietary kernel? I.e. not trying to figure out a solution for an upstream LTS kernel? > Can I try to directly malloc a 8 size buffer for kvm_mmio_fragment.data > instead of using kvm_mmio_fragment.val, and free this buffer in > complete_emulated_mmio when all fragments is been copied? I highly doubt that will work, because you'd still need to stash the pointer somewhere. And it pretty much would have to be somewhere in kvm_vcpu, which would likely mean a change in KABI. FWIW, freeing the allocation in complete_emulated_mmio() wouldn't suffice; you'd also need to free the memory on vCPU destruction, because there's no guarantee userspace would complete KVM_RUN. You should be able to use the padding in the "kvm_run.s". Thanks to s390's massive regs size, there's a huge amount of unused space in the union on x86. Note, because there can be two fragments in-flight, you'd need to index the array using the correct fragment number. Userspace can scribble the value, but that's completely irrelevant from a host safety perspective. diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6c8afa2047bf..29c7123d5467 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -515,7 +515,10 @@ struct kvm_run { __u64 kvm_valid_regs; __u64 kvm_dirty_regs; union { - struct kvm_sync_regs regs; + struct { + struct kvm_sync_regs regs; + u64 x86_mmio_val[2]; + }; char padding[SYNC_REGS_SIZE_BYTES]; } s; };