From nobody Sat Nov 15 22:25:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=googlemail.com ARC-Seal: i=1; a=rsa-sha256; t=1746167552; cv=none; d=zohomail.com; s=zohoarc; b=dt3wVHeWpArdzFnkXAJrO3KGVz3epfAF5lZnr18KB0zD9UC2CzJ4e9TBzORO650yqhXowWf/XPwP0H7CaHAXRHmYa54Y1EYD0ym7JmlvqvijIQe1kvxL5m/woLqf8XjemaJ3sazSi/9MFg4ygN5lLmAcdZ6YiMYsQpobZVxonoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746167552; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r9inCl48n/FEUF/d0F8bp05qecaBbZEla9jkg9JMco4=; b=j2TPwcrpmxX5Qj4SvbrHB1uVnp9FcidURAH5qWzzq99DIOWhuh5fSHVMiDeQnV8u+gEkOky86ZEliSVYfeHD1K1iCvVIll/BGu12sbJEkFj3UbzOupnfKFBRKinvu3E+ITEhQ/X2TB6HiK1myFKeAxOStUovE5CEW4t/K2lerJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1746167552558942.1224210100606; Thu, 1 May 2025 23:32:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uAjw5-0003zv-0V; Fri, 02 May 2025 02:31:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uAjw2-0003u5-OI for qemu-devel@nongnu.org; Fri, 02 May 2025 02:31:46 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uAjvz-00065y-Rp for qemu-devel@nongnu.org; Fri, 02 May 2025 02:31:45 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43cfe574976so9484345e9.1 for ; Thu, 01 May 2025 23:31:43 -0700 (PDT) Received: from outlast.lan (97e5422b.skybroadband.com. [151.229.66.43]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b8a315fdsm33495825e9.34.2025.05.01.23.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 May 2025 23:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1746167501; x=1746772301; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=r9inCl48n/FEUF/d0F8bp05qecaBbZEla9jkg9JMco4=; b=lSFRk+TvHT6W3dlHitSyVfHF+FddHNbANhl+OF50fNxt0+nAQFCDiKSkhMXQ4KKJNV 1/ZPt0MJdF6XjJeEwLMhGjmWLfak6mnNMufF/VPkIedWvaOPX7zxMlV06n5DqAufISg8 WSU3KIIZDRvbGuNkWF6KMQBNuza7Dg1c0KfqJmZdeuL+xcOQWbzqQYtw6FtzGKLQwQZ4 X+VFDXVPLIavQgD7fav/LNbn+ZNbSkg1SliiWY9vnZhmFee9xHChgMDUk82vuB7Ne0rv 7pOxHMgQIXk/hM+criXXDp+ywgCos+fTfpnJ1EBvCs+CmZ0RhWlSgp7+lhERmRFNisM+ sgnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746167501; x=1746772301; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r9inCl48n/FEUF/d0F8bp05qecaBbZEla9jkg9JMco4=; b=OeaXefx9xAAFXWdnTNHS5pQ2gxge+C7ILyCD8mEVN46q3FeMFH0nrxaDasDibUj6Q+ 38GXSjYbX+w5ETo6Xr6/ahIQ8VjIb54J2V5yVxU0TM9NPXZ4ehQPS0IJxG2qC32cIAQB xWFmjvyxCYEk7FZfpvfxpC/f+RnMO3ieus0c2HI8i/LaCcDfiBpde3Wos9JF0MCf2MY5 gvs6MsM91geVLEwNicI64FwZ4rN2uwF9S+Q4E3BOKuqtPO8GC47Ls0KXDkbG7uAlu5KV GtZQo/iXLlwB6vHrWEhZ7d/fWmyxVxnZeF6p7mTNmBON5M2djSOVa+NujsRQjgkAvk0U QSPQ== X-Gm-Message-State: AOJu0YyAeAvV7eEvU+bEGYL/9iycleUfhEmbaDuIxQvkrEDIhNCZKOHQ VzqSqrlK0yzaVcn/E5ZUPlE8MbX/p0lCcCKjs3zhz0iJeTeZJm4WWqrIz/mf1YY= X-Gm-Gg: ASbGnctUwcdANHXuW+FHKpoIrM04kW4/TmDeJ1grlNF9w7pl1xzpqjBoa7xc0s3Yjlm l5lX742qLtHEeFSrjHUEGrAxM38PbSuhxQBNEjHelkhX8P+Ui/8m6BwXkjPTejcQ0scfADsmcD4 /WznE86kCxj954gZJPoIq/efcQud4T5QmfUG3+CF/BY6UDwLcllMeaFt15lK3qjfYJjnVim5l6e 3RFWHo7YsEEGML4JrDJULALJrsZVYsWe0tAqiCBv3izbtkwY/2fdOrrwjir4Nw/GV8og8l2xzZs 92L3gs5VCRkjznOdbHizpxYKWgZVWcM3PdlNM5EUxlTKt5lNoKr0mWVL2osx+jz8Kvl2tdXfTqd ZiHBDFqwOrzAlWJVuhOJmQqMla6YmSsEUo1Y= X-Google-Smtp-Source: AGHT+IFetOIxjtohMyFBIhkkrElFUPug/X18R8L60ByKurSTPsZFNLJugb+0G8901KQO1uGeJX7QFw== X-Received: by 2002:a05:6000:1843:b0:3a0:8c3d:d7ed with SMTP id ffacd0b85a97d-3a099adcf68mr880319f8f.30.1746167500833; Thu, 01 May 2025 23:31:40 -0700 (PDT) From: WorksButNotTested X-Google-Original-From: WorksButNotTested <62701594+WorksButNotTested@users.noreply.github.com> To: qemu-devel@nongnu.org Cc: Laurent Vivier , Richard Henderson , Paolo Bonzini , WorksButNotTested <62701594+WorksButNotTested@users.noreply.github.com> Subject: [PATCH v2] Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user Date: Fri, 2 May 2025 07:31:40 +0100 Message-ID: <20250502063140.1098807-1-62701594+WorksButNotTested@users.noreply.github.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=jonwilson030981@googlemail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @googlemail.com) X-ZM-MESSAGEID: 1746167554698019000 Content-Type: text/plain; charset="utf-8" When running applications which make large (sparsely populated) address ran= ges (e.g. when using address sanitizer with LibAFL) the inability to exclude th= ese regions from any core dump can result in very large files which fill the di= sk. A coredump is obvously very useful for performing a post-mortem when fuzzin= g. Whilst the man pages state that madvise provides only a hint (and hence can= be ignored), this patch adds support to handle MADV_DONTDUMP and set a corresponding flag in the page flags, thus allowing QEMU to exclude these regions from the core file. Signed-off-by: WorksButNotTested <62701594+WorksButNotTested@users.noreply.= github.com> --- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/include/exec/page-protection.h b/include/exec/page-protection.h index c43231af8b..f8826d917e 100644 --- a/include/exec/page-protection.h +++ b/include/exec/page-protection.h @@ -38,4 +38,10 @@ */ #define PAGE_PASSTHROUGH 0x0800 =20 +/* + * For linux-user, indicates that the page should not be included in a cor= e=20 + * dump. + */ +#define PAGE_DONTDUMP 0x1000 + #endif diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fbfdec2f17..41c46da055 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, targ= et_ulong end, return 0; } =20 + if (flags & PAGE_DONTDUMP) { + return 0; + } + /* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from diff --git a/linux-user/mmap.c b/linux-user/mmap.c index f88a80c31e..62fc8ac921 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong l= en_in, int advice) */ mmap_lock(); switch (advice) { + case MADV_DONTDUMP: + if (len > 0) { + page_set_flags(start, start + len - 1, PAGE_DONTDUMP); + } + break; case MADV_WIPEONFORK: case MADV_KEEPONFORK: ret =3D -EINVAL; --=20 2.43.0