| 1 |
From a3ca86aea507904148870946d599e07a340b39bf Mon Sep 17 00:00:00 2001
|
| 2 |
From: Eugene Teo <eteo@redhat.com>
|
| 3 |
Date: Wed, 15 Jul 2009 14:59:10 +0800
|
| 4 |
Subject: Add '-fno-delete-null-pointer-checks' to gcc CFLAGS
|
| 5 |
|
| 6 |
From: Eugene Teo <eteo@redhat.com>
|
| 7 |
|
| 8 |
commit a3ca86aea507904148870946d599e07a340b39bf upstream.
|
| 9 |
|
| 10 |
Turning on this flag could prevent the compiler from optimising away
|
| 11 |
some "useless" checks for null pointers. Such bugs can sometimes become
|
| 12 |
exploitable at compile time because of the -O2 optimisation.
|
| 13 |
|
| 14 |
See http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Optimize-Options.html
|
| 15 |
|
| 16 |
An example that clearly shows this 'problem' is commit 6bf67672.
|
| 17 |
|
| 18 |
static void __devexit agnx_pci_remove(struct pci_dev *pdev)
|
| 19 |
{
|
| 20 |
struct ieee80211_hw *dev = pci_get_drvdata(pdev);
|
| 21 |
- struct agnx_priv *priv = dev->priv;
|
| 22 |
+ struct agnx_priv *priv;
|
| 23 |
AGNX_TRACE;
|
| 24 |
|
| 25 |
if (!dev)
|
| 26 |
return;
|
| 27 |
+ priv = dev->priv;
|
| 28 |
|
| 29 |
By reverting this patch, and compile it with and without
|
| 30 |
-fno-delete-null-pointer-checks flag, we can see that the check for dev
|
| 31 |
is compiled away.
|
| 32 |
|
| 33 |
call printk #
|
| 34 |
- testq %r12, %r12 # dev
|
| 35 |
- je .L94 #,
|
| 36 |
movq %r12, %rdi # dev,
|
| 37 |
|
| 38 |
Clearly the 'fix' is to stop using dev before it is tested, but building
|
| 39 |
with -fno-delete-null-pointer-checks flag at least makes it harder to
|
| 40 |
abuse.
|
| 41 |
|
| 42 |
Signed-off-by: Eugene Teo <eugeneteo@kernel.sg>
|
| 43 |
Acked-by: Eric Paris <eparis@redhat.com>
|
| 44 |
Acked-by: Wang Cong <amwang@redhat.com>
|
| 45 |
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
|
| 46 |
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
|
| 47 |
|
| 48 |
---
|
| 49 |
Makefile | 3 ++-
|
| 50 |
1 file changed, 2 insertions(+), 1 deletion(-)
|
| 51 |
|
| 52 |
--- a/Makefile
|
| 53 |
+++ b/Makefile
|
| 54 |
@@ -340,7 +340,8 @@ KBUILD_CPPFLAGS := -D__KERNEL__ $(LINUXI
|
| 55 |
|
| 56 |
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
|
| 57 |
-fno-strict-aliasing -fno-common \
|
| 58 |
- -Werror-implicit-function-declaration
|
| 59 |
+ -Werror-implicit-function-declaration \
|
| 60 |
+ -fno-delete-null-pointer-checks
|
| 61 |
KBUILD_AFLAGS := -D__ASSEMBLY__
|
| 62 |
|
| 63 |
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
|