lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <cover.1598518912.git.brookxu@tencent.com>
Date:   Thu, 27 Aug 2020 18:14:05 +0800
From:   Chunguang Xu <brookxu.cn@...il.com>
To:     arnd@...db.de
Cc:     rppt@...nel.org, linux-arch@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH 00/23] clean up the code related to ASSERT()

The kernel has not yet defined ASSERT(). Indeed, BUG() and WARN() are very
clear and can cover most application scenarios. However, some applications
require more debugging information and similar behavior to assert(), which
cannot be directly provided by BUG() and WARN().

Therefore, many modules independently implement ASSERT(), and most of them
are similar, but slightly different, such as:

 #define ASSERT(expr) \
         if(!(expr)) { \
                 printk( "\n" __FILE__ ":%d: Assertion " #expr " failed!\n",__LINE__); \
                 panic(#expr); \
         }

 #define ASSERT(x)                                                       \
 do {                                                                    \
         if (!(x)) {                                                     \
                 printk(KERN_EMERG "assertion failed %s: %d: %s\n",      \
                        __FILE__, __LINE__, #x);                         \
                 BUG();                                                  \
         }                                                               \
 } while (0)

Some implementations are not optimal for instruction prediction, such as
missing unlikely():

 #define assert(expr) \
         if(!(expr)) { \
         printk( "Assertion failed! %s,%s,%s,line=%d\n",\
         #expr,__FILE__,__func__,__LINE__); \
         BUG(); \
         }

Some implementations have too little log content information, such as:

 #define ASSERT(X)                                               \
 do {                                                            \
        if (unlikely(!(X))) {                                   \
                printk(KERN_ERR "\n");                          \
                printk(KERN_ERR "XXX: Assertion failed\n");     \
                BUG();                                          \
        }                                                       \
 } while(0)

As we have seen, This makes the code redundant and inconvenient to
troubleshoot the system. Therefore, perhaps we need to define two
wrappers for BUG() and WARN_ON(), such as ASSERT_FAIL() and
ASSERT_WARN(), provide the implementation of ASSERT(), simplify the
code and facilitate problem analysis.

Maybe I missed some information, but I think there is a need to clean
up the code, maybe in other ways, and more discussion is needed here.
If this approach is reasonable, I will clean up these codes later and
issue related patches.

Chunguang Xu (23):
  include/asm-generic/bug.h: add ASSERT_FAIL() and ASSERT_WARN() wrapper
  ia64: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  KVM: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  fore200e: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  scsi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  rxrpc: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  lib/mpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  jfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  cachefiles: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  btrfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  afs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  rivafb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  nvidia: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  fbdev/cirrusfb:: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  media/staging: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  sym53c8xx: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  8139too: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  net:hns: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  block/sx8: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  skb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  ext4: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  rbd: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
  ALSA: asihpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code

 arch/ia64/hp/common/sba_iommu.c                    |  6 +---
 arch/x86/kvm/ioapic.h                              |  9 +-----
 drivers/atm/fore200e.c                             |  6 +---
 drivers/block/rbd.c                                |  9 +-----
 drivers/block/skd_main.c                           |  8 +-----
 drivers/block/sx8.c                                |  6 +---
 drivers/net/ethernet/hisilicon/hns/hnae.h          |  8 +-----
 drivers/net/ethernet/realtek/8139too.c             |  6 +---
 drivers/scsi/megaraid/mega_common.h                | 10 ++-----
 drivers/scsi/sym53c8xx_2/sym_hipd.h                |  9 +-----
 .../pci/hive_isp_css_include/assert_support.h      |  6 +---
 drivers/video/fbdev/cirrusfb.c                     |  6 +---
 drivers/video/fbdev/nvidia/nvidia.c                |  7 +----
 drivers/video/fbdev/riva/fbdev.c                   |  7 +----
 fs/afs/internal.h                                  |  9 +-----
 fs/btrfs/ctree.h                                   | 12 +-------
 fs/cachefiles/internal.h                           |  9 +-----
 fs/ext4/mballoc.c                                  | 10 +------
 fs/jfs/jfs_debug.h                                 | 13 +--------
 include/asm-generic/bug.h                          | 33 ++++++++++++++++++++++
 lib/mpi/mpi-internal.h                             |  7 +----
 net/rxrpc/ar-internal.h                            |  8 +-----
 sound/pci/asihpi/hpidebug.h                        |  8 +-----
 23 files changed, 56 insertions(+), 156 deletions(-)

-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ