NetBSD Problem Report #57689
From www@netbsd.org Thu Nov 9 23:58:09 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 211971A9238
for <gnats-bugs@gnats.NetBSD.org>; Thu, 9 Nov 2023 23:58:09 +0000 (UTC)
Message-Id: <20231109235807.81A941A9239@mollari.NetBSD.org>
Date: Thu, 9 Nov 2023 23:58:07 +0000 (UTC)
From: rvp@SDF.ORG
Reply-To: rvp@SDF.ORG
To: gnats-bugs@NetBSD.org
Subject: getcwd() not overridable with -D_FORTIFY_SOURCE
X-Send-Pr-Version: www-1.0
>Number: 57689
>Category: lib
>Synopsis: getcwd() not overridable with -D_FORTIFY_SOURCE
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Nov 10 00:00:00 +0000 2023
>Last-Modified: Fri Nov 10 23:05:04 +0000 2023
>Originator: RVP
>Release: -HEAD, 10.x, 9.x
>Organization:
>Environment:
10.99.10 amd64
>Description:
getcwd() in libc is a weak symbol, but, you can't override it if compiled
with SSP & -O:
```
$ nm -D /lib/libc.so | fgrep getcwd
00000000000aea70 T __getcwd
00000000000a8ae0 T _getcwd
00000000000a8ae0 W _sys_getcwd
00000000000a8ae0 W getcwd
$ cat t.c
#include <err.h>
#include <errno.h>
#include <unistd.h>
char*
getcwd(char* buf, size_t buflen)
{
errno = ENOSYS;
return NULL;
}
int
main(void)
{
char buf[256];
if (getcwd(buf, sizeof buf) == NULL)
err(1, "getcwd failed");
return 0;
}
$ gcc -O2 -o g g.c
$ ./g
g: getcwd failed: Function not implemented
$ gcc -O2 -D_FORTIFY_SOURCE=2 -o g g.c
g.c:6:1: error: redefinition of ‘getcwd’
getcwd(char* buf, size_t buflen)
^~~~~~
In file included from /usr/include/ssp/unistd.h:34:0,
from /usr/include/unistd.h:74,
from g.c:3:
/usr/include/ssp/unistd.h:45:1: note: previous definition of ‘getcwd’ was here
__ssp_redirect_raw(char *, getcwd, getcwd, (char *__buf, size_t __len),
^
$
```
Should be pulled up to 10.x, 9.x, 8.x.
>How-To-Repeat:
As above.
>Fix:
Ref: gnu_inline attribute description in:
https://gcc.gnu.org/onlinedocs/gcc-10.5.0/gcc/Common-Function-Attributes.html
```
--- include/ssp/ssp.h.orig 2022-06-29 12:45:25.000000000 +0000
+++ include/ssp/ssp.h 2022-06-30 23:55:56.181039331 +0000
@@ -56,7 +56,7 @@
#endif
#define __ssp_real(fun) __ssp_real_(fun)
-#define __ssp_inline static __inline __attribute__((__always_inline__))
+#define __ssp_inline extern __inline __attribute__((__always_inline__, __gnu_inline__))
#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
```
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57689 CVS commit: src/tests/lib/libc/ssp
Date: Fri, 10 Nov 2023 18:03:25 -0500
Module Name: src
Committed By: christos
Date: Fri Nov 10 23:03:25 UTC 2023
Modified Files:
src/tests/lib/libc/ssp: Makefile t_ssp.sh
Added Files:
src/tests/lib/libc/ssp: h_getcwd2.c
Log Message:
PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libc/ssp/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/ssp/h_getcwd2.c
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/ssp/t_ssp.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57689 CVS commit: src/include/ssp
Date: Fri, 10 Nov 2023 18:03:37 -0500
Module Name: src
Committed By: christos
Date: Fri Nov 10 23:03:37 UTC 2023
Modified Files:
src/include/ssp: ssp.h
Log Message:
PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/include/ssp/ssp.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57689 CVS commit: src/distrib/sets/lists
Date: Fri, 10 Nov 2023 18:04:50 -0500
Module Name: src
Committed By: christos
Date: Fri Nov 10 23:04:50 UTC 2023
Modified Files:
src/distrib/sets/lists/debug: mi
src/distrib/sets/lists/tests: mi
Log Message:
Add test for:
PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE
To generate a diff of this commit:
cvs rdiff -u -r1.422 -r1.423 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1295 -r1.1296 src/distrib/sets/lists/tests/mi
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.