From patchwork Tue Nov 13 01:42:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10679473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2226214E2 for ; Tue, 13 Nov 2018 01:43:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 071B32A365 for ; Tue, 13 Nov 2018 01:43:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA7B42A3F9; Tue, 13 Nov 2018 01:43:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 88C412A365 for ; Tue, 13 Nov 2018 01:43:16 +0000 (UTC) Received: from localhost ([::1]:51545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMNjX-0006VG-Bg for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Nov 2018 20:43:15 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(MemoryRegion *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_accessor, mr, attrs); } + + return MEMTX_DECODE_ERROR; } 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_accessor, mr, attrs); } + + return MEMTX_DECODE_ERROR; } void memory_region_init_io(MemoryRegion *mr,