Skip to contentSkip to conversation

cve: fixes for Android

RFC PATCH New Petr Vorel 4 participants 20 messages Sep 2, 2017 – Sep 19, 2017

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

cover cve: fixes for Android

Hi,

Here some fixes to be able to build testcases/cve directory.

Kind regards,
Petr

Petr Vorel (6):
android: cve: Disable building cve-2017-5669
android: lib: Add missing include for tst_safe_pthread.h
android: Add pty.h header
android: cve: Fix build
android: cve/stack_clash: Fix PAGE_MASK defined in <sys/user.h>
android: cve/stack_clash: Fix warning

 include/android/pty.h         | 46 +++++++++++++++++++++++++++++++++++++++++++
 include/android/versioning.h  | 32 ++++++++++++++++++++++++++++++
 include/tst_safe_pthread.h    |  4 ++++
 testcases/cve/Makefile        |  7 +++++++
 testcases/cve/cve-2014-0196.c |  9 +++++++++
 testcases/cve/stack_clash.c   |  8 ++++----
 6 files changed, 102 insertions(+), 4 deletions(-)
 create mode 100644 include/android/pty.h
 create mode 100644 include/android/versioning.h
Signature · 1 line
2.14.0
author
#1 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

shmat() is not available on Android/Binder

---
 testcases/cve/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/Makefile +4 -0
index 04abc1f9c..5119c67cf 100644
@@ -28,4 +28,8 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 cve-2017-2671:	CFLAGS += -pthread
 cve-2017-2671:	LDLIBS += -lrt
 
+ifeq ($(ANDROID),1)
+FILTER_OUT_MAKE_TARGETS	+= cve-2017-5669
+endif
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 1 line
2.14.0
#2 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

(strictly, shmat is there in the c library, but (a) there's an selinux neverallow for sysv ipc and (b) it's compiled out of the kernel.)

Quoted 23 lines · Petr Vorel

shmat() is not available on Android/Binder

---
 testcases/cve/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/Makefile +4 -1
index 04abc1f9c..5119c67cf 100644
@@ -28,4 +28,8 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 cve-2017-2671: CFLAGS += -pthread
 cve-2017-2671: LDLIBS += -lrt
 
+ifeq ($(ANDROID),1)
+FILTER_OUT_MAKE_TARGETS        += cve-2017-5669
+endif
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
--

2.14.0

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
#3 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

In reply to Petr Vorel
Quoted 12 lines · Petr Vorel

shmat() is not available on Android/Binder

---
 testcases/cve/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/Makefile +0 -0
index 04abc1f9c..5119c67cf 100644

testcases/cve/Makefile cve-2014-0196: LDLIBS += -lrt -lutil · line 35

Quoted 8 lines
testcases/cve/Makefile +4 -0
@@ -28,4 +28,8 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 cve-2017-2671:	CFLAGS += -pthread
 cve-2017-2671:	LDLIBS += -lrt
 
+ifeq ($(ANDROID),1)
+FILTER_OUT_MAKE_TARGETS	+= cve-2017-5669
+endif
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk

Do you have pointers to how you are build + testing with this? There seem to be some duplication of effort that I would like to avoid and make sure there is only 1 way in which tests like this are disabled out of build.

I am currently working through a list[1] of disabled tests to make sure nothing has changed and will love to have a unified way of maintaining that list instead of doing it out-of-tree.

- ssp

1. https://android.googlesource.com/platform/external/ltp/+/master/android/tools/disabled_tests.txt

#4 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

Hi!

Quoted 15 lines
Quoted 15 lines

shmat() is not available on Android/Binder

---
 testcases/cve/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
testcases/cve/Makefile +0 -0
index 04abc1f9c..5119c67cf 100644
@@ -28,4 +28,8 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 cve-2017-2671:	CFLAGS += -pthread
 cve-2017-2671:	LDLIBS += -lrt
 
Quoted 9 lines

testcases/cve/Makefile cve-2014-0196: LDLIBS += -lrt -lutil · line 35

Quoted 5 lines
testcases/cve/Makefile +4 -0
+ifeq ($(ANDROID),1)
+FILTER_OUT_MAKE_TARGETS	+= cve-2017-5669
+endif
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk

Do you have pointers to how you are build + testing with this? There seem to be some duplication of effort that I would like to avoid and make sure there is only 1 way in which tests like this are disabled out of build.

There was some initiall android support done by Steven Jackson, just grep the git log for his name.

Basically what he did is to add a similar system we had for uClinux. You are supposed to define shell variable ANDROID=1 when building for android and the build system uses that to skip certain directories/files from build.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#5 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

In reply to Sandeep Patil

Hi,

Quoted 11 lines

Do you have pointers to how you are build + testing with this? There seem to be some duplication of effort that I would like to avoid and make sure there is only 1 way in which tests like this are disabled out of build.

I am currently working through a list[1] of disabled tests to make sure nothing has changed and will love to have a unified way of maintaining that list instead of doing it out-of-tree.

- ssp

1. https://android.googlesource.com/platform/external/ltp/+/master/android/tools/disabled_tests.txt

Great, it'd be nice to have working Android build (and not just everything disabled). Nice list, thanks for sharing.

BTW do you build with standalone toolchain? Which API level are you going to support?
https://android.googlesource.com/platform/ndk/+/master/build/tools/make-standalone-toolchain.sh

Kind regards,
Petr

#6 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

Quoted 13 lines · Petr Vorel

Hi,

Quoted 9 lines

Do you have pointers to how you are build + testing with this? There seem to be some duplication of effort that I would like to avoid and make sure there is only 1 way in which tests like this are disabled out of build.

I am currently working through a list[1] of disabled tests to make sure nothing has changed and will love to have a unified way of maintaining that list instead of doing it out-of-tree.

- ssp

Quoted 7 lines
Quoted 1 line

1. https://android.googlesource.com/platform/external/ltp/+/master/android/tools/disabled_tests.txt

Great, it'd be nice to have working Android build (and not just everything disabled). Nice list, thanks for sharing.

BTW do you build with standalone toolchain? Which API level are you going to support?
https://android.googlesource.com/platform/ndk/+/master/build/tools/make-standalone-toolchain.sh

(since none of the folks actually working on this seem to be responding...)

no, they don't, but effectively, yes: the standalone toolchain is the closest thing outside the platform build to what the platform build is like. (and it's almost always the right choice any time you're trying to build a non-Android linux project.)

as for the API level, because they're part of the platform build, in NDK terms they're targeting "FUTURE", which isn't available in the NDK. so you'll want 26 for now and then 27 when it's available and so on.

if you *really* care, you can litter the code with stuff like

  #if defined(__BIONIC__) && __ANDROID_API_LEVEL__ > 21
  // code that requires something that only appeared in Lollipop
  #endif

but these VTS folks only care about the current platform release. (because we can't suddenly go to OEMs and say "oh, that device you shipped three or four years ago now has to pass this new test" for obvious reasons :-) .)

one thing that's a little slippery is that there's stuff like SysV IPC where the headers and functions are available and if you're on a rooted device with a custom kernel, you can use it just fine, but actual shipping Android devices MUST NOT ship with kernels that support SysV IPC and MUST NOT relax the selinux neverallows that would prevent you from using that stuff even if it was compiled in to your kernel and so on... so there's a bit of a distinction between "i want to be able to build this project" and "i want all these tests to pass".

Quoted 2 lines

Kind regards,
Petr

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
author
#7 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

Hi,

Quoted 6 lines

(since none of the folks actually working on this seem to be responding...)

no, they don't, but effectively, yes: the standalone toolchain is the closest thing outside the platform build to what the platform build is like. (and it's almost always the right choice any time you're trying to build a non-Android linux project.)

Right, I should have realized from the link and Android.mk that you're building in AOSP tree :-).

Quoted 10 lines

as for the API level, because they're part of the platform build, in NDK terms they're targeting "FUTURE", which isn't available in the NDK. so you'll want 26 for now and then 27 when it's available and so on.

if you *really* care, you can litter the code with stuff like

  #if defined(__BIONIC__) && __ANDROID_API_LEVEL__ > 21
  // code that requires something that only appeared in Lollipop
  #endif

Well, even I posted code like this, I realized that flood the code with many ifdefs isn't desired for LTP upstream especially AOSP itself doesn't care about old releases.

Quoted 4 lines

but these VTS folks only care about the current platform release. (because we can't suddenly go to OEMs and say "oh, that device you shipped three or four years ago now has to pass this new test" for obvious reasons :-) .)

"Nice" embedded industry :-).

Quoted 9 lines

one thing that's a little slippery is that there's stuff like SysV IPC where the headers and functions are available and if you're on a rooted device with a custom kernel, you can use it just fine, but actual shipping Android devices MUST NOT ship with kernels that support SysV IPC and MUST NOT relax the selinux neverallows that would prevent you from using that stuff even if it was compiled in to your kernel and so on... so there's a bit of a distinction between "i want to be able to build this project" and "i want all these tests to pass".

Sure, successful build for android is the first step, IMHO the easier part. And after fixing tests written in C there would be another challenging task:
make all this shell scripts working on Android (IMHO impossible with toolbox, even with busybox would be hard).
OT: It'd be interesting to use LTP as a part of CTS to ensure that SysV IPC doesn't work :-).

Kind regards,
Petr

#8 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

Quoted 17 lines · Petr Vorel

Hi,

Quoted 6 lines

(since none of the folks actually working on this seem to be responding...)

no, they don't, but effectively, yes: the standalone toolchain is the closest thing outside the platform build to what the platform build is like. (and it's almost always the right choice any time you're trying to build a non-Android linux project.)

Right, I should have realized from the link and Android.mk that you're building in AOSP tree :-).

Quoted 4 lines

as for the API level, because they're part of the platform build, in NDK terms they're targeting "FUTURE", which isn't available in the NDK. so you'll want 26 for now and then 27 when it's available and so on.

Quoted 8 lines
Quoted 5 lines

if you *really* care, you can litter the code with stuff like

  #if defined(__BIONIC__) && __ANDROID_API_LEVEL__ > 21
  // code that requires something that only appeared in Lollipop
  #endif

Well, even I posted code like this, I realized that flood the code with many ifdefs isn't desired for LTP upstream especially AOSP itself doesn't care about old releases.

yeah, i don't think anyone would thank you for it :-)

Quoted 15 lines
Quoted 4 lines

but these VTS folks only care about the current platform release. (because we can't suddenly go to OEMs and say "oh, that device you shipped three or four years ago now has to pass this new test" for obvious reasons :-) .)

"Nice" embedded industry :-).

Quoted 9 lines

one thing that's a little slippery is that there's stuff like SysV IPC where the headers and functions are available and if you're on a rooted device with a custom kernel, you can use it just fine, but actual shipping Android devices MUST NOT ship with kernels that support SysV IPC and MUST NOT relax the selinux neverallows that would prevent you from using that stuff even if it was compiled in to your kernel and so on... so there's a bit of a distinction between "i want to be able to build this project" and "i want all these tests to pass".

Quoted 4 lines

Sure, successful build for android is the first step, IMHO the easier part. And after fixing tests written in C there would be another challenging task:
make all this shell scripts working on Android (IMHO impossible with toolbox, even with busybox would be hard).

toolbox is [mostly] long dead. current status:
https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/

(looks like i should update that to say where "O" occurred...)

if you have specific requests for missing commands/options, file them at the toybox github or android bug tracker (or just mail me directly).

Quoted 2 lines

OT: It'd be interesting to use LTP as a part of CTS to ensure that SysV IPC doesn't work :-).

i think they are using LTP as part of VTS
(https://source.android.com/devices/architecture/treble), which is why they're interested in building LTP with bionic for Android.

Quoted 2 lines

Kind regards,
Petr

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
#9 lore raw

RFC PATCH 1/6 android: cve: Disable building cve-2017-5669

(dropped the ball on this thread altogher...)

Quoted 20 lines · enh
Quoted 19 lines · Petr Vorel

Hi,

Quoted 6 lines

(since none of the folks actually working on this seem to be responding...)

no, they don't, but effectively, yes: the standalone toolchain is the closest thing outside the platform build to what the platform build is like. (and it's almost always the right choice any time you're trying to build a non-Android linux project.)

Right, I should have realized from the link and Android.mk that you're building in AOSP tree :-).

Quoted 6 lines

as for the API level, because they're part of the platform build, in NDK terms they're targeting "FUTURE", which isn't available in the NDK. so you'll want 26 for now and then 27 when it's available and so on.

if you *really* care, you can litter the code with stuff like

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
  #if defined(__BIONIC__) && __ANDROID_API_LEVEL__ > 21
  // code that requires something that only appeared in Lollipop
  #endif

Well, even I posted code like this, I realized that flood the code with many ifdefs isn't desired for LTP upstream especially AOSP itself doesn't care about old releases.

yeah, i don't think anyone would thank you for it :-)

Indeed :)

Quoted 30 lines
Quoted 16 lines
Quoted 5 lines

but these VTS folks only care about the current platform release. (because we can't suddenly go to OEMs and say "oh, that device you shipped three or four years ago now has to pass this new test" for obvious reasons :-) .)

"Nice" embedded industry :-).

Quoted 9 lines

one thing that's a little slippery is that there's stuff like SysV IPC where the headers and functions are available and if you're on a rooted device with a custom kernel, you can use it just fine, but actual shipping Android devices MUST NOT ship with kernels that support SysV IPC and MUST NOT relax the selinux neverallows that would prevent you from using that stuff even if it was compiled in to your kernel and so on... so there's a bit of a distinction between "i want to be able to build this project" and "i want all these tests to pass".

Quoted 4 lines

Sure, successful build for android is the first step, IMHO the easier part. And after fixing tests written in C there would be another challenging task:
make all this shell scripts working on Android (IMHO impossible with toolbox, even with busybox would be hard).

toolbox is [mostly] long dead. current status:
https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/

(looks like i should update that to say where "O" occurred...)

if you have specific requests for missing commands/options, file them at the toybox github or android bug tracker (or just mail me directly).

Quoted 6 lines
Quoted 2 lines

OT: It'd be interesting to use LTP as a part of CTS to ensure that SysV IPC doesn't work :-).

i think they are using LTP as part of VTS
(https://source.android.com/devices/architecture/treble), which is why they're interested in building LTP with bionic for Android.

Yes, LTP runs as part of VTS and that's the reason to get as many tests as possible working with bionic (atleast those that apply to Android.) Teh scripts and commands tests as we are finding out increasingly depend or make assumptions about the environment that are simply not true with Android. So, in *most* cases, they land in that "disabled_tests" list, for those that do work or are fixable with "available tools", we keep them around and they are run as part of VTS.

Also, FYI, there are tests in VTS that make sure certain kernel configurations are not set, thus making sure SYSV_IPC is never compiled in.

- ssp

author
#10 lore raw

RFC PATCH 2/6 android: lib: Add missing include for tst_safe_pthread.h

In reply to Petr Vorel

---
Maybe __ANDROID__ or __BIONIC__ should be used to test.

---
 include/tst_safe_pthread.h | 4 ++++
 1 file changed, 4 insertions(+)
include/tst_safe_pthread.h +4 -0
index 0242d4c76..0551f063f 100644
@@ -18,6 +18,10 @@
 #ifndef TST_SAFE_PTHREAD_H__
 #define TST_SAFE_PTHREAD_H__
 
+#ifdef __ANDROID_API__
+#include <pthread.h>
+#endif
+
 /*
  * Macro to use for making functions called only once in
  * multi-threaded tests such as init or cleanup function.
Signature · 1 line
2.14.0
#11 lore raw

RFC PATCH 2/6 android: lib: Add missing include for tst_safe_pthread.h

i'm not sure what's android-specific here. don't you want #include <pthread.h> or #include <sys/types.h> for all platforms, to get pthread_t and pthread_once_t?

Quoted 25 lines · Petr Vorel

---
Maybe __ANDROID__ or __BIONIC__ should be used to test.

---
 include/tst_safe_pthread.h | 4 ++++
 1 file changed, 4 insertions(+)
include/tst_safe_pthread.h +4 -1
index 0242d4c76..0551f063f 100644
@@ -18,6 +18,10 @@
 #ifndef TST_SAFE_PTHREAD_H__
 #define TST_SAFE_PTHREAD_H__
 
+#ifdef __ANDROID_API__
+#include <pthread.h>
+#endif
+
 /*
  * Macro to use for making functions called only once in
  * multi-threaded tests such as init or cleanup function.
--

2.14.0

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
author
#12 lore raw

RFC PATCH 3/6 android: Add pty.h header

In reply to Petr Vorel

Taken from Bionic, modified.

---
I needed to add #include "versioning.h".
I was tempted to use check
#if defined(__ANDROID_API__) && __ANDROID_API__ >= 23
instead of macro __INTRODUCED_IN(X) which causes warnings, but smaller delta won.

---
 include/android/pty.h        | 46 ++++++++++++++++++++++++++++++++++++++++++++
 include/android/versioning.h | 32 ++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 include/android/pty.h
 create mode 100644 include/android/versioning.h
include/android/pty.h new file +46 -0
new file mode 100644
index 000000000..dbcaad225
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _PTY_H
+#define _PTY_H
+
+#include <sys/cdefs.h>
+
+#include <termios.h>
+#include <sys/ioctl.h>
+
+#include "versioning.h"
+
+__BEGIN_DECLS
+
+int openpty(int* __master_fd, int* __slave_fd, char* __slave_name, const struct termios* __termios_ptr, const struct winsize* __winsize_ptr) __INTRODUCED_IN(23);
+int forkpty(int* __master_fd, char* __slave_name, const struct termios* __termios_ptr, const struct winsize* __winsize_ptr) __INTRODUCED_IN(23);
+
+__END_DECLS
+
+#endif
include/android/versioning.h new file +32 -0
new file mode 100644
index 000000000..4e1a1854c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VERSIONING_H
+#define ANDROID_VERSIONING_H
+
+#define __INTRODUCED_IN(api_level) __attribute__((annotate("introduced_in=" #api_level)))
+#define __INTRODUCED_IN_FUTURE __attribute__((annotate("introduced_in_future")))
+#define __DEPRECATED_IN(api_level) __attribute__((annotate("deprecated_in=" #api_level)))
+#define __REMOVED_IN(api_level) __attribute__((annotate("obsoleted_in=" #api_level)))
+#define __INTRODUCED_IN_32(api_level) __attribute__((annotate("introduced_in_32=" #api_level)))
+#define __INTRODUCED_IN_64(api_level) __attribute__((annotate("introduced_in_64=" #api_level)))
+#define __INTRODUCED_IN_ARM(api_level) __attribute__((annotate("introduced_in_arm=" #api_level)))
+#define __INTRODUCED_IN_X86(api_level) __attribute__((annotate("introduced_in_x86=" #api_level)))
+#define __INTRODUCED_IN_MIPS(api_level) __attribute__((annotate("introduced_in_mips=" #api_level)))
+
+#define __VERSIONER_NO_GUARD __attribute__((annotate("versioner_no_guard")))
+
+#endif /* ANDROID_VERSIONING_H */
Signature · 1 line
2.14.0
#13 lore raw

RFC PATCH 3/6 android: Add pty.h header

this seems very wrong. if you're going to do something like this, i think you should at least use __has_include_next and #include_next to get the real header if it exists and only supply your own if not. (but i'm not really sure what you're gaining here. you're turning a compile-time failure on old API levels into a link-time failure? and who exactly is running these tests on old versions of Android that they can't change anyway?)

Quoted 108 lines · Petr Vorel

Taken from Bionic, modified.

---
I needed to add #include "versioning.h".
I was tempted to use check
#if defined(__ANDROID_API__) && __ANDROID_API__ >= 23
instead of macro __INTRODUCED_IN(X) which causes warnings, but smaller delta won.

---
 include/android/pty.h        | 46 ++++++++++++++++++++++++++++++++++++++++++++
 include/android/versioning.h | 32 ++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 include/android/pty.h
 create mode 100644 include/android/versioning.h
include/android/pty.h new file +46 -0
new file mode 100644
index 000000000..dbcaad225
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _PTY_H
+#define _PTY_H
+
+#include <sys/cdefs.h>
+
+#include <termios.h>
+#include <sys/ioctl.h>
+
+#include "versioning.h"
+
+__BEGIN_DECLS
+
+int openpty(int* __master_fd, int* __slave_fd, char* __slave_name, const struct termios* __termios_ptr, const struct winsize* __winsize_ptr) __INTRODUCED_IN(23);
+int forkpty(int* __master_fd, char* __slave_name, const struct termios* __termios_ptr, const struct winsize* __winsize_ptr) __INTRODUCED_IN(23);
+
+__END_DECLS
+
+#endif
include/android/versioning.h new file +32 -1
new file mode 100644
index 000000000..4e1a1854c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VERSIONING_H
+#define ANDROID_VERSIONING_H
+
+#define __INTRODUCED_IN(api_level) __attribute__((annotate("introduced_in=" #api_level)))
+#define __INTRODUCED_IN_FUTURE __attribute__((annotate("introduced_in_future")))
+#define __DEPRECATED_IN(api_level) __attribute__((annotate("deprecated_in=" #api_level)))
+#define __REMOVED_IN(api_level) __attribute__((annotate("obsoleted_in=" #api_level)))
+#define __INTRODUCED_IN_32(api_level) __attribute__((annotate("introduced_in_32=" #api_level)))
+#define __INTRODUCED_IN_64(api_level) __attribute__((annotate("introduced_in_64=" #api_level)))
+#define __INTRODUCED_IN_ARM(api_level) __attribute__((annotate("introduced_in_arm=" #api_level)))
+#define __INTRODUCED_IN_X86(api_level) __attribute__((annotate("introduced_in_x86=" #api_level)))
+#define __INTRODUCED_IN_MIPS(api_level) __attribute__((annotate("introduced_in_mips=" #api_level)))
+
+#define __VERSIONER_NO_GUARD __attribute__((annotate("versioner_no_guard")))
+
+#endif /* ANDROID_VERSIONING_H */
--

2.14.0

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
author
#14 lore raw

RFC PATCH 4/6 android: cve: Fix build of most of the tests

In reply to Petr Vorel
---
 testcases/cve/Makefile        | 3 +++
 testcases/cve/cve-2014-0196.c | 9 +++++++++
 2 files changed, 12 insertions(+)
testcases/cve/Makefile +3 -0
index 5119c67cf..7c8917569 100644
@@ -19,6 +19,7 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 CFLAGS			+= -D_GNU_SOURCE
 
+ifneq ($(ANDROID),1)
 cve-2016-7117:	CFLAGS += -pthread
 cve-2016-7117:	LDLIBS += -lrt
 
@@ -27,9 +28,11 @@ cve-2014-0196:  LDLIBS += -lrt -lutil
 
 cve-2017-2671:	CFLAGS += -pthread
 cve-2017-2671:	LDLIBS += -lrt
+endif
 
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= cve-2017-5669
+CPPFLAGS		+= -I$(abs_srcdir)/../../include/android
 endif
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/cve/cve-2014-0196.c +9 -0
index 4e2b3f582..87fea2781 100644
@@ -34,6 +34,7 @@
  * privilege escalation POC https://www.exploit-db.com/exploits/33516/
  */
 
+#if !defined(__ANDROID_API__) || __ANDROID_API__ >= 23
 #include <pty.h>
 #include <stdio.h>
 #include <string.h>
@@ -159,3 +160,11 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.test_all = run,
 };
+#else /* Android API < 23 */
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+int main(void)
+{
+	tst_brk(TCONF, "test does not run on Android API < 23");
+}
+#endif
Signature · 1 line
2.14.0
#15 lore raw

RFC PATCH 4/6 android: cve: Fix build of most of the tests

Hi!

Quoted 1 line

+#if !defined(__ANDROID_API__) || __ANDROID_API__ >= 23

This looks ugly to me.

What is the exact problem here? Do the test fail to compile there? If so we should really check for the missing feature and enable/disable the test based on that rather than this hackery.

Quoted 21 lines

#include <pty.h>
#include <stdio.h>
#include <string.h>

testcases/cve/cve-2014-0196.c +8 -0
@@ -159,3 +160,11 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.test_all = run,
 };
+#else /* Android API < 23 */
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+int main(void)
+{
+	tst_brk(TCONF, "test does not run on Android API < 23");
+}
+#endif
Signature · 5 lines
2.14.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#16 lore raw

RFC PATCH 5/6 android: cve/stack_clash: Fix PAGE_MASK defined in <sys/user.h>

In reply to Petr Vorel

clash is caused by including <sys/wait.h>

---
 testcases/cve/stack_clash.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/cve/stack_clash.c +3 -3
index 082d362e9..2d2984824 100644
@@ -48,7 +48,7 @@
 #include "tst_safe_stdio.h"
 
 static unsigned long page_size;
-static unsigned long PAGE_MASK;
+static unsigned long page_mask;
 static unsigned long GAP_PAGES = 256;
 static unsigned long THRESHOLD;
 static int STACK_GROWSDOWN;
@@ -169,7 +169,7 @@ void do_child(void)
 	else
 		mapped_addr = stack_addr + gap;
 
-	mapped_addr &= PAGE_MASK;
+	mapped_addr &= page_mask;
 	map = SAFE_MMAP((void *)mapped_addr, MAPPED_LEN,
 			PROT_READ|PROT_WRITE,
 			MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
@@ -201,7 +201,7 @@ void setup(void)
 	char buf[4096], *p;
 
 	page_size = sysconf(_SC_PAGESIZE);
-	PAGE_MASK = ~(page_size - 1);
+	page_mask = ~(page_size - 1);
 
 	buf[4095] = '\0';
 	SAFE_FILE_SCANF("/proc/cmdline", "%4095[^\n]", buf);
Signature · 1 line
2.14.0
author
#18 lore raw

RFC PATCH 6/6 android: cve/stack_clash: Fix warning

In reply to Petr Vorel

format '%lx' expects argument of type 'long unsigned int', but argument 8 has type 'ssize_t'

Still some warnings left in cve.

---
 testcases/cve/stack_clash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/cve/stack_clash.c +1 -1
index 2d2984824..ee537a3c5 100644
@@ -85,7 +85,7 @@ void segv_handler(int sig, siginfo_t *info, void *data LTP_ATTRIBUTE_UNUSED)
 
 	tst_res(TINFO,
 		"mmap = [%lx, %lx), addr = %lx, diff = %lx, THRESHOLD = %lx",
-		mapped_addr, mmap_end, fault_addr, diff, THRESHOLD);
+		mapped_addr, mmap_end, fault_addr, (long)diff, THRESHOLD);
 	if (diff < 0 || (unsigned long)diff < THRESHOLD)
 		_exit(EXIT_FAILURE);
 	else
Signature · 1 line
2.14.0
#19 lore raw

RFC PATCH 6/6 android: cve/stack_clash: Fix warning

Hi!

Quoted 1 line

format '%lx' expects argument of type 'long unsigned int', but argument 8 has type 'ssize_t'

ssize_t should be printed by %zi these days

Signature · 2 lines
Cyril Hrubis
[email protected]