tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

SSP cleanup



Hi all,
attached patch is the implementation of the change I suggested on
source-changes-d a few days ago. It removes most of the changes required
for SSP support. One open question is whether we just want to drop
_sys_* or keep them as weak symbols for now.

This has been tested on AMD64 with the default settings and USE_FORT=no.

Joerg
Index: src/include/ssp/ssp.h
===================================================================
--- src/include/ssp/ssp.h
+++ src/include/ssp/ssp.h
@@ -1,9 +1,9 @@
 /*     $NetBSD: ssp.h,v 1.8 2011/01/26 18:08:00 christos Exp $ */
 
 /*-
- * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
  * by Christos Zoulas.
  *
@@ -38,19 +38,22 @@
 #  if _FORTIFY_SOURCE > 1
 #   define __SSP_FORTIFY_LEVEL 2
 #  else
 #   define __SSP_FORTIFY_LEVEL 1
 #  endif
+# else
+#  define __SSP_FORTIFY_LEVEL 0
 # endif
+#else
+# define __SSP_FORTIFY_LEVEL 0
 #endif
 
-#ifndef __ssp_weak_name
-#ifdef _NAMESPACE_H_
-#define __ssp_weak_name(fun) _sys ## fun
+/* __ssp_real is used by the implementation in libc */
+#if __SSP_FORTIFY_LEVEL == 0
+#define __ssp_real(fun)        fun
 #else
-#define __ssp_weak_name(fun) _sys_ ## fun
-#endif
+#define __ssp_real(fun)        __ssp_real_ ## fun
 #endif
 
 #define __ssp_inline static __inline __attribute__((__always_inline__))
 
 #define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
@@ -57,24 +60,24 @@
 #define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
 
 #define __ssp_check(buf, len, bos) \
        if (bos(buf) != (size_t)-1 && len > bos(buf)) \
                __chk_fail()
-#define __ssp_redirect_raw(rtype, fun, args, call, bos) \
-rtype __ssp_weak_name(fun) args; \
-__ssp_inline rtype fun args; \
+#define __ssp_redirect_raw(rtype, fun, symbol, args, call, bos) \
+rtype __ssp_real(fun) args __RENAME(symbol); \
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \
 __ssp_inline rtype fun args { \
        __ssp_check(__buf, __len, bos); \
-       return __ssp_weak_name(fun) call; \
+       return __ssp_real(fun) call; \
 }
 
 #define __ssp_redirect(rtype, fun, args, call) \
-    __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos)
+    __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos)
 #define __ssp_redirect0(rtype, fun, args, call) \
-    __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos0)
+    __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos0)
 
 __BEGIN_DECLS
 void __stack_chk_fail(void) __dead;
 void __chk_fail(void) __dead;
 __END_DECLS
 
 #endif /* _SSP_SSP_H_ */

Index: src/lib/libc/gen/getcwd.c
===================================================================
--- src/lib/libc/gen/getcwd.c
+++ src/lib/libc/gen/getcwd.c
@@ -52,19 +52,12 @@
 #include <unistd.h>
 
 #include "extern.h"
 
 #ifdef __weak_alias
-__weak_alias(getcwd,_sys_getcwd)
-__weak_alias(_getcwd,_sys_getcwd)
+__weak_alias(getcwd,_getcwd)
 __weak_alias(realpath,_realpath)
-
-#if defined(_FORTIFY_SOURCE) && !defined(__lint__)
-#undef getcwd
-#define getcwd _sys_getcwd
-#endif
-
 #endif
 
 /*
  * char *realpath(const char *path, char resolved[MAXPATHLEN]);
  *
@@ -211,11 +204,11 @@
        path = q;
        goto loop;
 }
 
 char *
-getcwd(char *pt, size_t size)
+__ssp_real(_getcwd)(char *pt, size_t size)
 {
        char *npt;
 
        /*
         * If a buffer is specified, the size has to be non-zero.



Home | Main Index | Thread Index | Old Index