From owner-freebsd-hackers@freebsd.org Sat Oct 17 04:29:48 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D15D2428C99 for ; Sat, 17 Oct 2020 04:29:48 +0000 (UTC) (envelope-from karnajitw@gmail.com) Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CCqmq6K7bz4bRv for ; Sat, 17 Oct 2020 04:29:47 +0000 (UTC) (envelope-from karnajitw@gmail.com) Received: by mail-yb1-xb2c.google.com with SMTP id x20so3632280ybs.8 for ; Fri, 16 Oct 2020 21:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DRuGQ2HAkdSR/G0DqodhFi18XTHaWdYxQkoKGfbfnsA=; b=DPyO15+5WNhh/kByO8s9oPtiAHuXBz4bqHhMUrXIHtaDKynttmcXxKT9gfS8jY67kk DZx0G4GlD/XJw0JF5anBCc06/drep37T6rfmLT8TjWxhCVGgeHObJD5SzALkpin7ub9Q +FASmz+jdR0PFRq6GaICg+bWHlTBEzmSbuiNpOWz4jjySJx22dorDF+ABOQ9nQeTBZ3H Z++iaQa8fycWFnvjBoXXKKeWqkC7HAtlT+LklxAe5ZMjL4OYoVKlctNtvJ+K8btjgETV DrlDJok6OJP5/JP/ZLzZB+7C3bhAylvKkVOaykO/JWxjwCX1lwxEd8fssnU5bvyZTBL4 5VKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DRuGQ2HAkdSR/G0DqodhFi18XTHaWdYxQkoKGfbfnsA=; b=Cb9W43W2OKOgFHkzqfq80qFKRuH83ibJjel4Kgqvxfj0AV3BGiN6hG4wvk+xd8XkBc yJv5w8grWJj2Uk+68GzuC1i9BsZ+Rq2QOnGO1yNdjIHr8LlGqtFoJ2jqHxsbYq0s9oVr tocdexKICmLsdddgOS+PUVd5TqY7WfWLd9Xhzec6ZSbmgWdn/przZEecYoqM+/Psnpkt GdrBzYzV3tcDgcEXm2lp064MzUH60aiAJb8v/YsKlhghZnBtQTFI42WlQ0ynXEYZmw0o ewq0DH1M77UuWFQ9QJ2rcAUjID2m7EG2yZbkMWPDr1nnKZOLmwWO7JAMO4k1aHNeX3o1 3t2A== X-Gm-Message-State: AOAM5334tNR+cJT7q0HpKtFxAD5FOeGlAOzHdvbKI/h8UvCsyopMUOMR HVu2gcm1Z0r+1KU76lCqW4DU4HsKRqNIiPYEP9s= X-Google-Smtp-Source: ABdhPJyqQNW+SfwHWh/7PlINZ9L+4ZFlEjvDbN1EEO6LYNsJpzy/NfO6etzPXIJcMAIxFIgSXeCOXNROwvZWRZhNyQY= X-Received: by 2002:a25:810c:: with SMTP id o12mr9024639ybk.198.1602908986828; Fri, 16 Oct 2020 21:29:46 -0700 (PDT) MIME-Version: 1.0 References: <9CCF59F6-06F2-4352-94E5-C508E165D0C2@wanadoo.fr> In-Reply-To: From: karnajit wangkhem Date: Sat, 17 Oct 2020 09:59:35 +0530 Message-ID: Subject: Re: Extra memory mapping seen on freebsd-12 which was not seen in freebsd-11 To: Paul Floyd Cc: FreeBSD Hackers X-Rspamd-Queue-Id: 4CCqmq6K7bz4bRv X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=DPyO15+5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of karnajitw@gmail.com designates 2607:f8b0:4864:20::b2c as permitted sender) smtp.mailfrom=karnajitw@gmail.com X-Spamd-Result: default: False [-2.96 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.97)[-0.975]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; NEURAL_HAM_LONG(-0.99)[-0.994]; NEURAL_SPAM_SHORT(0.01)[0.011]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::b2c:from]; FREEMAIL_TO(0.00)[wanadoo.fr]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-hackers]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Oct 2020 04:29:48 -0000 Hi Paul, The mappings of these applications existed prior to the guard change, which was fine as no mapping existed on the memory range. With migration to stable 12, I was doubting that these mappings are no longer correct. But at the same time, does valgrind have to own this segment, which only came post certain freebsd releases? Regards, Karan On Sat, Oct 17, 2020 at 12:39 AM Paul Floyd wrote: > > > > On 16 Oct 2020, at 07:13, karnajit wangkhem wrote= : > > > > Thanks for the reply. It helped in my understanding. > > > > Below is a sample code > > > > #include > > #include > > #include > > #include > > > > int main() > > { > > char *str =3D NULL; > > str =3D (char *)mmap((void *)0x7fffdfffe000UL, 0x2000, PROT_READ | > > PROT_WRITE, MAP_FIXED | MAP_ANON, -1, 0); > > if ((void *)str =3D=3D (void *)MAP_FAILED) { > > int err =3D errno; > > printf("mmap failed. err (%s)\n", strerror(err)); > > } else { > > memcpy(str, "Hello World", 12); > > printf("str =3D %s\n", str); > > } > > > > return 0; > > } > > > > Now, the below code under valgrind will give > > - mmap failed. err (Invalid argument) > > > > But, if we give control of this segment to the client program > > with VG_(am_change_ownership_v_to_c), then valgrind allows the client t= o > do > > the following mmap. > > - str =3D Hello World > > > > And, the resultant procstat result looks like this: > > 2382 0x7fbfff000 0x7fc001000 rwx 2 2 1 0 ----- = df > > 2382 0x7fffdfffe000 0x7fffe0000000 rw- 0 0 0 0 ----- = -- > > <<< Client mmap call > > 2382 0x7fffe0000000 0x7ffffffdf000 --- 0 0 0 0 ----- = -- > > <<< 0x1000 bytes is taken away from the MAP_GUARD area > > 2382 0x7ffffffdf000 0x7ffffffff000 rw- 1 1 1 0 ---D- = df > > 2382 0x7ffffffff000 0x800000000000 r-x 1 1 104 0 ----- = ph > > > > So, is it right for the application with or without valgrind to cross t= he > > above boundary, If that memory which the application reserved is just f= or > > normal application specific use? > > Hi > > Obviously threre are some restrictions for the guest application running > under Valgrind. > Valgrind needs its own stack and heap, so the guest can=E2=80=99t mmap th= ese > regions. > > Why do you need to mmap into this region? > > A+ > Paul > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= " >