From nobody Fri May 3 03:49:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154207341033428.865680515369377; Mon, 12 Nov 2018 17:43:30 -0800 (PST) Received: from localhost ([::1]:51545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMNjk-0006VG-J5 for importer@patchew.org; Mon, 12 Nov 2018 20:43:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMNir-0005w4-U9 for qemu-devel@nongnu.org; Mon, 12 Nov 2018 20:42:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMNim-0002Zo-RJ for qemu-devel@nongnu.org; Mon, 12 Nov 2018 20:42:32 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41672) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gMNim-0002ZW-KO for qemu-devel@nongnu.org; Mon, 12 Nov 2018 20:42:28 -0500 Received: by mail-pf1-x444.google.com with SMTP id e22-v6so5178777pfn.8 for ; Mon, 12 Nov 2018 17:42:28 -0800 (PST) Received: from localhost.localdomain.localdomain ([103.65.40.100]) by smtp.gmail.com with ESMTPSA id m10-v6sm34178213pfg.180.2018.11.12.17.42.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 17:42:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=z0N09Y0cst6nqVUkgrKxDzze99eXooTttgdzYhrS/Vs=; b=C/QWBFTzgnT7FTO3gMfXfAWF/d6b9RpfR8OpADFVBd5UzX7bZe83N1keAZ89UQNQRl pDv1emSCXbeI4fwTNW/IqUnhS7oS+9QWG+1bAls6VAJPXGRt8v9dADsmNwCsM40dCvcm EiWpsFhGb/XKAjwBFAdGHSPYYAOK5Sxj81Hv/u1RIE6xFyxVBkSSt2RAm3tcim+Futti +/jYAcAUiUuZNCZqMVqe2kZBk8Ku9+eVuygItgJAynClxdfPU4V+5PFMtLCjkkctog7M 3nc6/x5QXQwHkWcNT15VHxWv7LOe39A7zqSqagOgHd7gEsWRAlxzGpdQbgNXWUtWCxbE GXhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z0N09Y0cst6nqVUkgrKxDzze99eXooTttgdzYhrS/Vs=; b=AIlzft6Io0DuLRBCII1G1gTBPs4I11DsUKvF6ybG+50jdhfAI5XjGAudWmYppYnHlq uCW211/JxSrMk2NvliuGCrraRIQLPYnJwI/rwyM7+uCMp2cDnd2eBPoBUCFuQHG7UiX8 /HsIrXJg7EK55lNnuhG0rhdfu5bhiwTaSN3/ClMscyV4lCnL8JF/BE8zhD7Y6b4w7ioL 4X6wjPKpWdVgeZLStGx61bEmBMV3ZSjXgV8YIQwu8kB/lXZxMQQ0m4Jf/3sYOwovjdBM D81wq3gPjHZbeGpQNOVPXopaHNRnDX1i/oG9AwE03IiqrHhAeoS1Fo/wWIg5URhBjYDF jaBw== X-Gm-Message-State: AGRZ1gI6RZWWbq9zOMgRRDrSrdEvglZc00Nefzl6R5U/oICD+Zza0UU3 Rbd/+d5hpxPXRchURhv54cc= X-Google-Smtp-Source: AJdET5fsOt+4vtNmB6pOS2Bk8zFSdMSbGpavBW4CTzPApy4yI5E/IEA/XILCLefTJlFhjwkhRRVNyA== X-Received: by 2002:a63:83c1:: with SMTP id h184mr2923053pge.437.1542073347396; Mon, 12 Nov 2018 17:42:27 -0800 (PST) From: Li Qiang To: pbonzini@redhat.com, peter.maydell@linaro.org, marcandre.lureau@gmail.com, ppandit@redhat.com Date: Mon, 12 Nov 2018 17:42:21 -0800 Message-Id: <1542073341-2843-1-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This can avoid the NULL-deref if the rm doesn't has a read/write nor write/read_with_attrs callback. Signed-off-by: Li Qiang --- memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/memory.c b/memory.c index d14c6dec1d..3baf5857b9 100644 --- a/memory.c +++ b/memory.c @@ -1377,13 +1377,15 @@ static MemTxResult memory_region_dispatch_read1(Mem= oryRegion *mr, mr->ops->impl.max_access_size, memory_region_read_accessor, mr, attrs); - } else { + } else if (mr->ops->read_with_attrs) { return access_with_adjusted_size(addr, pval, size, mr->ops->impl.min_access_size, mr->ops->impl.max_access_size, memory_region_read_with_attrs_acc= essor, mr, attrs); } + + return MEMTX_DECODE_ERROR; } =20 MemTxResult memory_region_dispatch_read(MemoryRegion *mr, @@ -1454,7 +1456,7 @@ MemTxResult memory_region_dispatch_write(MemoryRegion= *mr, mr->ops->impl.max_access_size, memory_region_write_accessor, mr, attrs); - } else { + } else if (mr->ops->write_with_attrs) { return access_with_adjusted_size(addr, &data, size, mr->ops->impl.min_access_size, @@ -1462,6 +1464,8 @@ MemTxResult memory_region_dispatch_write(MemoryRegion= *mr, memory_region_write_with_attrs_acces= sor, mr, attrs); } + + return MEMTX_DECODE_ERROR; } =20 void memory_region_init_io(MemoryRegion *mr, --=20 2.11.0