From nobody Wed Feb 28 20:46:52 2024 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TlRH03pR6z5CNvV for ; Wed, 28 Feb 2024 20:46:52 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TlRH00flCz4YWL for ; Wed, 28 Feb 2024 20:46:52 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709153212; a=rsa-sha256; cv=none; b=tlmFIAjYRpgDEVgAAOYGfQIvnsLbhZoNIJDqB1j94G+qbkyXp2PTcRbjJq6kb+i3+imsKC INCn91ewLhpOTDsgcpy7Qygg1hf3P+D9B11o5+K5BjKSvgmvZv/w+AeO7XQjgnbpso8SLp iQrHiJVwyyXPhBm2RdX8n8+0tgwteES5PNmmon/Ji0R2YSMlIqJ3tVgaYQq0wDSyuxKJdD IWt31sWuBBCNLWC1Wb9xNKezPFPxszWBxuK30QICYMz7nq9hoK2Nxp4wP3HWTj/Eh1b2xe MW4sIhe5FcfxuACFJ8rxvdAuPJpdu//VL1Hfc2riXdR8oDnQR7RQKydDCqgn3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709153212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=C4gIeBQV/tRYtVGnDWM01Uqw3S7oKTg+YQkD3ARZXy0=; b=ppxOhwtxKusEqUpd+qglGqCKkmKlydGNQ538N8EU/Lt0w/Kx3JXKgJ38k8P9KMqt5KACi8 g4NYRj3wQcQiDu3xJoog/qJ3ieRV3DBMSwdG5pmmRFpImhU0ZAHgd4dH64N3cZVIlOc92l MsfMbQrMUroH086crK6hGEJ2mgJek/kBWJJYIKqzTyqODAnGkjMGwD7bVTX+ceNIzDLu92 DrNRnk02Mk5Sb74Yk0J5Fk/gIapmrBob235lyT4oY3p/b5AjWcBiFr4DV1m+9fy4ACxqXh LvzJVXkw4ZVTvJV+qIpH+5jG1yMBUwU7XhM16RPz7fY9T73+1eg75lfc+dH/fg== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TlRGz6qyYz1C47 for ; Wed, 28 Feb 2024 20:46:51 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 41SKkpWX043119 for ; Wed, 28 Feb 2024 20:46:51 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 41SKkpBp043117 for bugs@FreeBSD.org; Wed, 28 Feb 2024 20:46:51 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 277382] Wrong stack growth for amd64 pthread stacks Date: Wed, 28 Feb 2024 20:46:52 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 14.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: pjfloyd@wanadoo.fr X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D277382 Bug ID: 277382 Summary: Wrong stack growth for amd64 pthread stacks Product: Base System Version: 14.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: pjfloyd@wanadoo.fr I've been trying to diagnose a Valgrind regression test failure since I mov= ed to using FreeBSD 14.0. The test deliberately exceeds the thread's stack: static void bad_things_till_guard_page(void) { char j =3D 0; char *p =3D &j; for (;;) { j =3D j + *p; p =3D p - 400; lowest_j =3D p; } } Then it tries to describe where the eventual segfault happens. Prior to 14.= 0 it correctly worked out that it was in the guard page below the stack. Not it = just say below the stack. Not the end of the world. Here's what I see is happening. When the stack is allocated, there is an mmap for 2M+4k. The bottom 4k is t= hen mprotect'd to have PROT_NONE mmap(0x1ffedfe000,2101248,PROT_READ|PROT_WRITE,MAP_FIXED|MAP_STACK,-1,0x0) = =3D 137420070912 (0x1ffedfe000) mprotect(0x1ffedfe000,4096,PROT_NONE) =3D 0 (0x0) Now that 2M above the guard page gets subdivided. The bottom 128k (controll= ed by kern.sgrowsiz) is marked as the RW grow down stack and the remaining 2M-= 128k is the growth guard area. As the thread uses more an more of its stack the kernel will use up the free space 128k at a time. Apart from the last chunk. That will be 128k - 4k (the 4k is controlled by security.bsd.stack_guard_page which is in pages, default of 1). So at the e= nd there are, by default, two 4k guard pages left. That looks like a bug to me.=20 Back to Valgrind. All of those changes to the kern.sgrowsiz blocks of the s= tack are invisible to Valgrind. It sees the 2M+4k mmap and the 4k mprotect so it thinks that there is 2M of RW stack and then a 4k guard page. But the segfa= ult doesn't happen in the lowest guard page, it happens in the second one that = is above that. Valgrind doesn't see that as PROT_NONE so it fails to figure out that it is a kind of guard page. --=20 You are receiving this mail because: You are the assignee for the bug.=