All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/5] Fortify strscpy()
@ 2020-11-18 11:07 laniel_francis
  2020-11-18 11:07 ` [PATCH v5 1/5] string.h: detect intra-object overflow in fortified string functions laniel_francis
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: laniel_francis @ 2020-11-18 11:07 UTC (permalink / raw)
  To: akpm; +Cc: linux-hardening, linux-mm, linux-kernel, dja, keescook,
	Francis Laniel

From: Francis Laniel <laniel_francis@privacyrequired.com>

Hi.


I hope your families, friends and yourselves are fine.

This patch set answers to this issue:
https://github.com/KSPP/linux/issues/46

I based my modifications on top of two patches from Daniel Axtens which modify
calls to __builtin_object_size to ensure the true size of char * are returned
and not the surrounding structure size.

To sum up, in my first patch I implemented a fortified version of strscpy.
This new version ensures the following before calling vanilla strscpy:
1. There is no read overflow because either size is smaller than src length
or we shrink size to src length by calling fortified strnlen.
2. There is no write overflow because we either failed during compilation or at
runtime by checking that size is smaller than dest size.
The second patch brings a new file in LKDTM driver to test this new version.
The test ensures the fortified version still returns the same value as the
vanilla one while panic'ing when there is a write overflow.
The third just corrects some typos in LKDTM related file.

If you see any problem or way to improve the code, feel free to share it.


Best regards.

Daniel Axtens (2):
  string.h: detect intra-object overflow in fortified string functions
  lkdtm: tests for FORTIFY_SOURCE

Francis Laniel (3):
  string.h: Add FORTIFY coverage for strscpy()
  Add new file in LKDTM to test fortified strscpy.
  Correct wrong filenames in comment.

 drivers/misc/lkdtm/Makefile             |  1 +
 drivers/misc/lkdtm/bugs.c               | 50 +++++++++++++++
 drivers/misc/lkdtm/core.c               |  3 +
 drivers/misc/lkdtm/fortify.c            | 82 +++++++++++++++++++++++++
 drivers/misc/lkdtm/lkdtm.h              | 19 +++---
 include/linux/string.h                  | 75 ++++++++++++++++++----
 tools/testing/selftests/lkdtm/tests.txt |  1 +
 7 files changed, 213 insertions(+), 18 deletions(-)
 create mode 100644 drivers/misc/lkdtm/fortify.c

-- 
2.20.1


^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [PATCH v5 4/5] Add new file in LKDTM to test fortified strscpy.
@ 2020-11-18 20:15 kernel test robot
  0 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2020-11-18 20:15 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 4204 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20201118110731.15833-5-laniel_francis@privacyrequired.com>
References: <20201118110731.15833-5-laniel_francis@privacyrequired.com>
TO: laniel_francis(a)privacyrequired.com
TO: akpm(a)linux-foundation.org
CC: linux-hardening(a)vger.kernel.org
CC: linux-mm(a)kvack.org
CC: linux-kernel(a)vger.kernel.org
CC: dja(a)axtens.net
CC: keescook(a)chromium.org
CC: Francis Laniel <laniel_francis@privacyrequired.com>

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on kselftest/next linus/master hnaz-linux-mm/master v5.10-rc4 next-20201118]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/laniel_francis-privacyrequired-com/Fortify-strscpy/20201118-190826
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 93c69b2d17372463ae33b79b3002c22a208945b3
:::::: branch date: 9 hours ago
:::::: commit date: 9 hours ago
config: ia64-randconfig-s031-20201118 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-107-gaf3512a6-dirty
        # https://github.com/0day-ci/linux/commit/b8ce9dd880f1853b99ef29a47088fe8f9c2bf885
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review laniel_francis-privacyrequired-com/Fortify-strscpy/20201118-190826
        git checkout b8ce9dd880f1853b99ef29a47088fe8f9c2bf885
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


"sparse warnings: (new ones prefixed by >>)"
   drivers/misc/lkdtm/fortify.c: note: in included file:
   drivers/misc/lkdtm/lkdtm.h:5:9: sparse: sparse: preprocessor token pr_fmt redefined
   drivers/misc/lkdtm/fortify.c: note: in included file (through include/linux/kernel.h, include/asm-generic/bug.h, arch/ia64/include/asm/bug.h, ...):
>> include/linux/printk.h:301:9: sparse: this was the original definition

vim +301 include/linux/printk.h

01c313dded34a16 Arnd Bergmann   2017-11-13  286  
90c165f0de3adad Ricardo Cañuelo 2020-04-03  287  /**
90c165f0de3adad Ricardo Cañuelo 2020-04-03  288   * pr_fmt - used by the pr_*() macros to generate the printk format string
90c165f0de3adad Ricardo Cañuelo 2020-04-03  289   * @fmt: format string passed from a pr_*() macro
90c165f0de3adad Ricardo Cañuelo 2020-04-03  290   *
90c165f0de3adad Ricardo Cañuelo 2020-04-03  291   * This macro can be used to generate a unified format string for pr_*()
90c165f0de3adad Ricardo Cañuelo 2020-04-03  292   * macros. A common use is to prefix all pr_*() messages in a file with a common
90c165f0de3adad Ricardo Cañuelo 2020-04-03  293   * string. For example, defining this at the top of a source file:
90c165f0de3adad Ricardo Cañuelo 2020-04-03  294   *
90c165f0de3adad Ricardo Cañuelo 2020-04-03  295   *        #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
90c165f0de3adad Ricardo Cañuelo 2020-04-03  296   *
90c165f0de3adad Ricardo Cañuelo 2020-04-03  297   * would prefix all pr_info, pr_emerg... messages in the file with the module
90c165f0de3adad Ricardo Cañuelo 2020-04-03  298   * name.
90c165f0de3adad Ricardo Cañuelo 2020-04-03  299   */
968ab1838a5d48f Linus Torvalds  2010-11-15  300  #ifndef pr_fmt
968ab1838a5d48f Linus Torvalds  2010-11-15 @301  #define pr_fmt(fmt) fmt
968ab1838a5d48f Linus Torvalds  2010-11-15  302  #endif
968ab1838a5d48f Linus Torvalds  2010-11-15  303  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 33857 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-11-19 16:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-18 11:07 [PATCH v5 0/5] Fortify strscpy() laniel_francis
2020-11-18 11:07 ` [PATCH v5 1/5] string.h: detect intra-object overflow in fortified string functions laniel_francis
2020-11-18 11:07 ` [PATCH v5 2/5] lkdtm: tests for FORTIFY_SOURCE laniel_francis
2020-11-18 11:07 ` [PATCH v5 3/5] string.h: Add FORTIFY coverage for strscpy() laniel_francis
2020-11-18 11:07 ` [PATCH v5 4/5] Add new file in LKDTM to test fortified strscpy laniel_francis
2020-11-18 20:02   ` Kees Cook
2020-11-19 16:29     ` Francis Laniel
2020-11-18 20:58   ` kernel test robot
2020-11-18 20:58     ` kernel test robot
2020-11-19  4:36   ` kernel test robot
2020-11-19  4:36     ` kernel test robot
2020-11-18 11:07 ` [PATCH v5 5/5] Correct wrong filenames in comment laniel_francis
  -- strict thread matches above, loose matches on Subject: below --
2020-11-18 20:15 [PATCH v5 4/5] Add new file in LKDTM to test fortified strscpy kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.