Skip to contentSkip to conversation

safestringlib: add recipe

PATCH In review Naveen Saini 2 participants 3 messages Jul 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 safestringlib: add recipe

The Secure Development Lifecycle (SDL) recommends banning certain C Library functions because they directly contribute to security vulnerabilities such as buffer overflows.

However routines for the manipulation of strings and memory buffers are common in software and firmware, and are essential to accomplish certain programming tasks.

Safer replacements for these functions that avoid or prevent serious security vulnerabilities (e.g. buffer overflows, string format attacks, conversion overflows/underflows, etc.) are available in the SafeString Library.

Ref:
https://github.com/intel/safestringlib

---
 .../safestringlib/safestringlib_git.bb        | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 meta-oe/recipes-support/safestringlib/safestringlib_git.bb
meta-oe/recipes-support/safestringlib/safestringlib_git.bb new file +28 -0
new file mode 100644
index 000000000..1ca594412
@@ -0,0 +1,28 @@
+SUMMARY = "Safe string operations and memory routines"
+SECTION = "libs"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://LICENSE&COPYING.txt;md5=edd6f8c4c1072d72645ae28cb04bdbce \
+                    file://LICENSE;md5=54f68ba2c33474320fcc46b1f2d01249"
+
+SRC_URI = "git://github.com/intel/safestringlib.git;protocol=https \
+        "
+
+PV = "1.0.0+git${SRCPV}"
+SRCREV = "245c4b8cff1d2e7338b7f3a82828fc8e72b29549"
+
+S = "${WORKDIR}/git"
+
+inherit pkgconfig cmake
+
+COMPATIBLE_HOST = '(x86_64.*|i.86.*)-linux'
+
+do_install() {
+    install -d ${D}${libdir}
+    install -d ${D}${includedir}
+    install -m 0644 ${B}/libsafestring_shared.so ${D}${libdir}
+    install -m 0644 ${B}/libsafestring_static.a ${D}${libdir}
+    install -m 0644 ${S}/include/*.h ${D}${includedir}
+}
+
+SOLIBS = ".so"
+FILES_SOLIBSDEV = ""
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/2 safestringlib: add ptest

---
 .../safestringlib/enable-logs-for-ptest.patch | 28 +++++++++++++++++
 .../exclude-test-wmemmove-s-ptest.patch       | 30 +++++++++++++++++++
 .../safestringlib/safestringlib/run-ptest     | 10 +++++++
 .../safestringlib/safestringlib_git.bb        | 14 ++++++++-
 4 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-support/safestringlib/safestringlib/enable-logs-for-ptest.patch
 create mode 100644 meta-oe/recipes-support/safestringlib/safestringlib/exclude-test-wmemmove-s-ptest.patch
 create mode 100755 meta-oe/recipes-support/safestringlib/safestringlib/run-ptest
meta-oe/recipes-support/safestringlib/safestringlib/enable-logs-for-ptest.patch new file +28 -0
new file mode 100644
index 000000000..4707b9e01
@@ -0,0 +1,28 @@
+From 0375758a2225394bcf766e3d5c3611c44ea967f7 Mon Sep 17 00:00:00 2001
+From: Naveen Saini <[email protected]>
+Date: Thu, 9 Jul 2020 13:12:05 +0800
+Subject: [PATCH] unittests/CMakeLists.txt: define DEBUG for logs
+
+Required for ptest testcase.
+
+Upstream-Status: Inappropriate
+
+Signed-off-by: Naveen Saini <[email protected]>
+---
+ unittests/CMakeLists.txt | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
+index 88cd835..9b285b2 100644
+--- a/unittests/CMakeLists.txt
++++ b/unittests/CMakeLists.txt
+@@ -1,5 +1,6 @@
+ cmake_minimum_required(VERSION 3.1)
+ project(safestring_test)
++add_compile_definitions(DEBUG)
+ 
+ set(SOURCES
+   Safe_String_UnitTestMain.c
+-- 
+2.17.1
+
meta-oe/recipes-support/safestringlib/safestringlib/exclude-test-wmemmove-s-ptest.patch new file +30 -0
new file mode 100644
index 000000000..85ce97060
@@ -0,0 +1,30 @@
+From 669ac8ccbf7259239ccfd3f2a4a6e53a3c69ad09 Mon Sep 17 00:00:00 2001
+From: Naveen Saini <[email protected]>
+Date: Wed, 8 Jul 2020 17:47:20 +0800
+Subject: [PATCH] unittests/Safe_String_UnitTestMain.c: exclude test_wmemmove_s
+
+test_wmemmove_s cause segmentation fault, exclude it for now
+
+Upstream-Status: Inappropriate
+
+Signed-off-by: Naveen Saini <[email protected]>
+---
+ unittests/Safe_String_UnitTestMain.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/unittests/Safe_String_UnitTestMain.c b/unittests/Safe_String_UnitTestMain.c
+index fa40511..e4b7e31 100644
+--- a/unittests/Safe_String_UnitTestMain.c
++++ b/unittests/Safe_String_UnitTestMain.c
+@@ -159,7 +159,7 @@ int main(void) {
+ 	test_wcsncpy_s(); /* New - Done */
+ 	test_wcsnlen_s(); /* New - Done */
+ 	test_wmemcpy_s(); /* New - Done */
+-	test_wmemmove_s(); /* New - Done */
++//	test_wmemmove_s(); /* New - Done */
+ 	test_wmemset_s(); /* New - Done */
+ 	test_wmemcmp_s(); /* New - Done */
+ 
+-- 
+2.17.1
+
meta-oe/recipes-support/safestringlib/safestringlib/run-ptest new file +10 -0
new file mode 100755
index 000000000..e426929e8
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+cd unittests
+TOTALFAILS=$(./safestring_test  | grep Error | wc -l)
+if [ $TOTALFAILS -eq 0 ]; then
+  echo "PASS: safestring test"
+else
+  echo "FAIL: safestring  test"
+  echo "Total Saftstring tests failed: $TOTALFAILS"
+fi
meta-oe/recipes-support/safestringlib/safestringlib_git.bb +13 -1
index 1ca594412..c171fa238 100644
@@ -5,6 +5,9 @@ LIC_FILES_CHKSUM = "file://LICENSE&COPYING.txt;md5=edd6f8c4c1072d72645ae28cb04bd
                     file://LICENSE;md5=54f68ba2c33474320fcc46b1f2d01249"
 
 SRC_URI = "git://github.com/intel/safestringlib.git;protocol=https \
+           file://exclude-test-wmemmove-s-ptest.patch \
+           file://enable-logs-for-ptest.patch \
+           file://run-ptest \
         "
 
 PV = "1.0.0+git${SRCPV}"
@@ -12,7 +15,11 @@ SRCREV = "245c4b8cff1d2e7338b7f3a82828fc8e72b29549"
 
 S = "${WORKDIR}/git"
 
-inherit pkgconfig cmake
+inherit pkgconfig cmake ptest
+
+EXTRA_OECMAKE += " \
+                   ${@bb.utils.contains('DISTRO_FEATURES', 'ptest', '-DBUILD_UNITTESTS=ON', '', d)} \
+                "
 
 COMPATIBLE_HOST = '(x86_64.*|i.86.*)-linux'
 
@@ -24,5 +31,10 @@ do_install() {
     install -m 0644 ${S}/include/*.h ${D}${includedir}
 }
 
+do_install_ptest () {
+    install -d ${D}${PTEST_PATH}/unittests
+    install -m 0755 ${B}/unittests/safestring_test ${D}${PTEST_PATH}/unittests
+}
+
 SOLIBS = ".so"
 FILES_SOLIBSDEV = ""
Signature · 1 line
2.17.1
#2 lore raw
In reply to Naveen Saini
Quoted 35 lines · Naveen Saini

The Secure Development Lifecycle (SDL) recommends banning certain C Library functions because they directly contribute to security vulnerabilities such as buffer overflows.

However routines for the manipulation of strings and memory buffers are common in software and firmware, and are essential to accomplish certain programming tasks.

Safer replacements for these functions that avoid or prevent serious security vulnerabilities (e.g. buffer overflows, string format attacks, conversion overflows/underflows, etc.) are available in the SafeString Library.

Ref:
https://github.com/intel/safestringlib

---
 .../safestringlib/safestringlib_git.bb        | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 meta-oe/recipes-support/safestringlib/safestringlib_git.bb
meta-oe/recipes-support/safestringlib/safestringlib_git.bb new file +7 -0
new file mode 100644
index 000000000..1ca594412
@@ -0,0 +1,28 @@
+SUMMARY = "Safe string operations and memory routines"
+SECTION = "libs"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://LICENSE&COPYING.txt;md5=edd6f8c4c1072d72645ae28cb04bdbce \
+                    file://LICENSE;md5=54f68ba2c33474320fcc46b1f2d01249"
+
+SRC_URI = "git://github.com/intel/safestringlib.git;protocol=https \

meta-oe/recipes-support/safestringlib/safestringlib_git.bb line 17

Quoted 10 lines
meta-oe/recipes-support/safestringlib/safestringlib_git.bb new file +10 -0
+        "
+
+PV = "1.0.0+git${SRCPV}"
+SRCREV = "245c4b8cff1d2e7338b7f3a82828fc8e72b29549"
+
+S = "${WORKDIR}/git"
+
+inherit pkgconfig cmake
+
+COMPATIBLE_HOST = '(x86_64.*|i.86.*)-linux'

Since we already have safec in meta-oe which works across more architectures and has more coverage too
I see less of a point of including this package in meta-oe, perhaps meta-intel is a better location for this if it
only helps x86

Quoted 15 lines
meta-oe/recipes-support/safestringlib/safestringlib_git.bb new file +11 -1
+
+do_install() {
+    install -d ${D}${libdir}
+    install -d ${D}${includedir}
+    install -m 0644 ${B}/libsafestring_shared.so ${D}${libdir}
+    install -m 0644 ${B}/libsafestring_static.a ${D}${libdir}
+    install -m 0644 ${S}/include/*.h ${D}${includedir}
+}
+
+SOLIBS = ".so"
+FILES_SOLIBSDEV = ""
--

2.17.1