From nobody Fri Nov 14 20:27:39 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=1590492065; cv=none; d=zohomail.com; s=zohoarc; b=YaFSr9eG7Msff5yyEw8IqxF9Da30MnTTLuDCOvdsP12cZrvZ3qEt/dyPtCQM2RsuhW4eiZkZSDl93WvzhpE3DfgOjSxs+GLrnvfULge4VjxbRdRALM/ePSdTG8PdZOSarhy9fDZzYMuDoQrof3/1jGEdHQ1eheY6nXHHYGbsTYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590492065; 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=VfYe3erQLI9NlxuT5QwYIt7bkNUp+Qn0Puxot75N2Hg=; b=Vjq+Oyd4oY/jhhvufQPJapp4O6r3tbYD0927ztvWUuPuwFki6aL2C6wlFMf1VaSnjJ5NKqxOb0ZDJyWGLaEnXXPjfgSZk25WgcC9lbFcTvMcOyi+yCCup7UfYsp+Ca9b15jHZnfyayjxoHSeWxFI0Vwv5P1HWmZivXUEdjPilPc= 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 1590492065248818.1022586395972; Tue, 26 May 2020 04:21:05 -0700 (PDT) Received: from localhost ([::1]:59150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdXdn-0002Ip-9Y for importer@patchew.org; Tue, 26 May 2020 07:21:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdXcw-0001Hg-WD for qemu-devel@nongnu.org; Tue, 26 May 2020 07:20:11 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37833 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 1jdXcw-0007Mr-1g for qemu-devel@nongnu.org; Tue, 26 May 2020 07:20:10 -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-14-tM5TY2AlOkmVe-uZ_EMD4w-1; Tue, 26 May 2020 07:19:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92FDA1005510; Tue, 26 May 2020 11:19:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.74.8.233]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 094B05C1BE; Tue, 26 May 2020 11:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590492008; 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=VfYe3erQLI9NlxuT5QwYIt7bkNUp+Qn0Puxot75N2Hg=; b=B7i1DvLxZIPZFyneYlkek/0qbDe4nbQsazYpcxmhudzUcvArc5D2PeEsrY5dYF+nZcNiBR lgY7SZiFhLrxvz/AtrcQXSypOWpS8GpZuPjOqJ6X6703eZguCeuuWFKVvn8lAwiHEdA/DY pEmo2oYYUjqcMA7Uv7YYLhSzgMTaIqc= X-MC-Unique: tM5TY2AlOkmVe-uZ_EMD4w-1 From: P J P To: Paolo Bonzini Subject: [PATCH v4] exec: set map length to zero when returning NULL Date: Tue, 26 May 2020 16:47:43 +0530 Message-Id: <20200526111743.428367-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/05/26 01:19:28 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Fam Zheng , Peter Maydell , Prasad J Pandit , QEMU Developers , Alexander Bulekov , Ding Ren , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 mapping physical memory into host's virtual address space, 'address_space_map' may return NULL if BounceBuffer is in_use. Set and return '*plen =3D 0' to avoid later NULL pointer dereference. Reported-by: Alexander Bulekov Fixes: https://bugs.launchpad.net/qemu/+bug/1878259 Suggested-by: Paolo Bonzini Suggested-by: Peter Maydell Signed-off-by: Prasad J Pandit Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- exec.c | 1 + include/exec/memory.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) Update v4: update address_space_map API doc text -> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html diff --git a/exec.c b/exec.c index 5162f0d12f..4eea84bf66 100644 --- a/exec.c +++ b/exec.c @@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as, =20 if (!memory_access_is_direct(mr, is_write)) { if (atomic_xchg(&bounce.in_use, true)) { + *plen =3D 0; return NULL; } /* Avoid unbounded allocations */ diff --git a/include/exec/memory.h b/include/exec/memory.h index e000bd2f97..8fa2d3cab2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwa= ddr addr, hwaddr len, /* address_space_map: map a physical memory region into a host virtual add= ress * * May map a subset of the requested range, given by and returned in @plen. - * May return %NULL if resources needed to perform the mapping are exhaust= ed. + * May return %NULL and set *@plen to zero(0), if resources needed to perf= orm + * the mapping are exhausted. * Use only for reads OR writes - not for read-modify-write operations. * Use cpu_register_map_client() to know when retrying the map operation is * likely to succeed. --=20 2.26.2