From nobody Sat Nov 15 01:02:00 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592482578; cv=none; d=zohomail.com; s=zohoarc; b=b87HgCiyT+YxYSQLWhXPRAYGLnlnbYlVYrlNV/TGfGKyMRKBpl+2PWrCgnc94Hua/wHrefFG7WYE+4BsvDkbE6tS6S85Rm78TuqyZ1IyFwjHVjpZ51+FI9Wyx0+BxCoxa2RHcFXgb8CWIjj2/hil+66IVteGi7B08XbJ1a3Q6NU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592482578; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=BqgcYS0MIdVPDVQzytea64k+zZrG7Asl8VfW0xFTbeY=; b=b/KtQet7gx2tHt046cUfTGOWyXjuSxn24WVGXRgWOHcZ/oEEb1/0b/dP5Xi83mNzKJh8P5a8N1lfM6wrlBivOmrsQNcU1cOKYSYbMWDukun/MX+Aap7pw/bhWN97pZudCcHL6T2FyNYk4wRwHEDYi8h3E6Qr2UYbEiYPZMPzocY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159248257848573.84180471805792; Thu, 18 Jun 2020 05:16:18 -0700 (PDT) Received: from localhost ([::1]:34346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jltSq-0002lN-4o for importer@patchew.org; Thu, 18 Jun 2020 08:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jltRI-0001fY-Ic for qemu-devel@nongnu.org; Thu, 18 Jun 2020 08:14:40 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40717 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jltRG-0001OC-GO for qemu-devel@nongnu.org; Thu, 18 Jun 2020 08:14:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-399xKMsnM-6lXPxjLvWHGA-1; Thu, 18 Jun 2020 08:14:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2EDE51054FA4; Thu, 18 Jun 2020 12:14:32 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-52.phx2.redhat.com [10.3.112.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB04F60BF3; Thu, 18 Jun 2020 12:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592482477; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BqgcYS0MIdVPDVQzytea64k+zZrG7Asl8VfW0xFTbeY=; b=asaWiwMg/ScHbfq2/C/ucx2VR5puPmo9LPY5Vy5EL5fIWFWqdzj0HPl3ry7v1oEoprVf/U 9r4bpPovgitmrv6agTXa5kc3FOkuYFTauLVYnUot4oxuZpEkIq06dIuiK5q+qG3Y3dHAHP aD0+7i18NEDV4lfqLK7gopCV0isQqFs= X-MC-Unique: 399xKMsnM-6lXPxjLvWHGA-1 From: P J P To: Paolo Bonzini Subject: [PATCH v1] memory: assert MemoryRegionOps callbacks are defined Date: Thu, 18 Jun 2020 17:42:18 +0530 Message-Id: <20200618121218.215808-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=205.139.110.120; envelope-from=ppandit@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/18 01:21:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Li Qiang , QEMU Developers , Lei Sun , Alex Williamson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit When registering a MemoryRegionOps object, assert that its read/write callback methods are defined. This avoids potential guest crash via a NULL pointer dereference. Suggested-by: Peter Maydell Signed-off-by: Prasad J Pandit --- memory.c | 5 +++++ 1 file changed, 5 insertions(+) Update v1: add assert while registering MemoryRegionOps -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg05187.html diff --git a/memory.c b/memory.c index 91ceaf9fcf..6e94fd5958 100644 --- a/memory.c +++ b/memory.c @@ -1495,6 +1495,9 @@ void memory_region_init_io(MemoryRegion *mr, const char *name, uint64_t size) { + assert(ops); + assert(ops->read); + assert(ops->write); memory_region_init(mr, owner, name, size); mr->ops =3D ops ? ops : &unassigned_mem_ops; mr->opaque =3D opaque; @@ -1674,6 +1677,8 @@ void memory_region_init_rom_device_nomigrate(MemoryRe= gion *mr, { Error *err =3D NULL; assert(ops); + assert(ops->read); + assert(ops->write); memory_region_init(mr, owner, name, size); mr->ops =3D ops; mr->opaque =3D opaque; --=20 2.26.2