From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lBFYZ-0000j8-2W for mharc-qemu-trivial@gnu.org; Sun, 14 Feb 2021 06:27:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBFYV-0000hF-Ut for qemu-trivial@nongnu.org; Sun, 14 Feb 2021 06:27:11 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:39283) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lBFYU-0006Yr-Au for qemu-trivial@nongnu.org; Sun, 14 Feb 2021 06:27:11 -0500 Received: by mail-wr1-x431.google.com with SMTP id v1so5187301wrd.6 for ; Sun, 14 Feb 2021 03:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=fgpf2oSanHx19OymtjolGlxytQ4BcgHG1wsnBAtY3Pw=; b=rWC/ltCcxLJOeYYM9N+/Q5H6tnNgrjNajpoqT0JbDAjUh1iwEyKlF3ciaukTnrFfHi /tsFgrrTUaJV3yMm5/rquLLGDYySl67x89vWIX0E0+Ihf4pWEfz/VWTYjVnhOPf/XC8/ ufS2K3FwjDFF4VJ5A1t2BcaR1oIGS0O3cpTeAQa7cjeUE0d4l4nwvpSO5xcnH9RBF8u8 GrRWunhNrzd3xOHkjci7ClQoAXGZJJmD9MQS5oPhN/jNoQFf/LIx8ds7vgfOW/zEguFU 7jVHguPZ3R7peQ4r+eV8bKgyEvhqS+Cd81vQ8jOPxItQ3/KGL52b5BvKZo26U18msW2U r5uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :in-reply-to:message-id:mime-version:content-transfer-encoding; bh=fgpf2oSanHx19OymtjolGlxytQ4BcgHG1wsnBAtY3Pw=; b=taabbvK/hlroBXokLMd8S5oUMuCjIztQBtSLuC+G7GkyriORprI3ycsuiNOaYLp4qM OBBHib7p3L6yPnIm8KRHJ/l6uWNmikKChaNDBYrcAIidIikKKDvzEGWa+8Tze5ZHjyv1 QaEPqkpaiOg90wt2VeuRh8qS6OHrDSWOk3PWIamiNTIxpETATL/8VW4ler+xg1zlyttI v31hRz6P1mLAm35lFSMH4Z7GSxUe74XO8yAnAJZCZJC5CyAnBbPkC7SNpPQHcv5a+iCt 8H+ZHEMUdAevoH42ROEdcPhMF8vzYlIQaTqNEDoSLy6bIy/IrGCjAEtZ8kwXqBj2zvGg CT4g== X-Gm-Message-State: AOAM533MLcQybemATRhQD+UrBKGBFkLufSbvDF0UCJvG+LnK0Xuous8g vgTZWLvnTKYdP2rduAGR5pSBfQ== X-Google-Smtp-Source: ABdhPJwH/XOjgHceGfHEv/yaMSOjbNj2mcL2I8Jbwp5RUCfF7hUO+Bbda6PZ1qEdBmaapz0VeRHHNQ== X-Received: by 2002:adf:dc83:: with SMTP id r3mr13755198wrj.53.1613302028237; Sun, 14 Feb 2021 03:27:08 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l1sm19081653wmi.48.2021.02.14.03.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 03:27:07 -0800 (PST) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 509201FF7E; Sun, 14 Feb 2021 11:27:06 +0000 (GMT) References: <20210131061930.14554-1-vfazio@xes-inc.com> User-agent: mu4e 1.5.8; emacs 28.0.50 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Vincent Fazio Cc: qemu-trivial@nongnu.org, laurent@vivier.eu, Vincent Fazio , qemu-devel@nongnu.org Subject: Re: [PATCH] linux-user/elfload: do not assume MAP_FIXED_NOREPLACE kernel support Date: Sun, 14 Feb 2021 11:24:57 +0000 In-reply-to: <20210131061930.14554-1-vfazio@xes-inc.com> Message-ID: <87o8gmc2k5.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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-trivial@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Feb 2021 11:27:12 -0000 Vincent Fazio writes: > From: Vincent Fazio > > Previously, pgd_find_hole_fallback assumed that if the build host's libc > had MAP_FIXED_NOREPLACE defined that the address returned by mmap would > match the requested address. This is not a safe assumption for Linux > kernels prior to 4.17 It doesn't as we have in osdep.h: #ifndef MAP_FIXED_NOREPLACE #define MAP_FIXED_NOREPLACE 0 #endif which is to say to assume if MAP_FIXED_NOREPLACE is defined the kernel should have given us what we want otherwise we do the check. > > Now, we always compare mmap's resultant address with the requested > address and no longer short-circuit based on MAP_FIXED_NOREPLACE. > > Fixes: 2667e069e7b5 ("linux-user: don't use MAP_FIXED in pgd_find_hole_fa= llback") > Signed-off-by: Vincent Fazio > --- > linux-user/elfload.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/linux-user/elfload.c b/linux-user/elfload.c > index 5f5f23d2e5..8d425f9ed0 100644 > --- a/linux-user/elfload.c > +++ b/linux-user/elfload.c > @@ -2217,8 +2217,7 @@ static uintptr_t pgd_find_hole_fallback(uintptr_t g= uest_size, uintptr_t brk, > PROT_NONE, flags, -1, 0); > if (mmap_start !=3D MAP_FAILED) { > munmap(mmap_start, guest_size); > - if (MAP_FIXED_NOREPLACE !=3D 0 || > - mmap_start =3D=3D (void *) align_start) { > + if (mmap_start =3D=3D (void *) align_start) { > return (uintptr_t) mmap_start + offset; > } > } --=20 Alex Benn=C3=A9e