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: <tencent_1647475C9618C390BEC601BE2CC1206D0C07@qq.com>
Date:   Tue, 25 Apr 2023 20:00:14 +0800
From:   Yangyu Chen <cyy@...self.name>
To:     Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>
Cc:     linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
        Wende Tan <twd2.me@...il.com>, Soha Jin <soha@...u.info>,
        Hongren Zheng <i@...ithal.me>, Yangyu Chen <cyy@...self.name>
Subject: [PATCH 0/2] Allow case-insensitive RISC-V ISA string

According to RISC-V ISA specification, the ISA naming strings are
case insensitive. The kernel docs require the riscv,isa string must
be all lowercase to simplify parsing currently. However, this 
limitation is not consistent with RISC-V ISA Spec.

The motivation for this patch series is that some SoC generators
will provide ISA strings with uppercase letters in the device tree.
For example, the rocket-chip will have "Zicsr_Zifencei_Zihpm_Xrocket"
in the ISA string. If we did not modify the ISA string manually, the
parser in the current kernel will have errors when the pointer meets
uppercase letters because it assumes the string only has digits, 
lowercase letters, and underscores. Then, the parser will fail and
the pointer of the parser will continue at the next position, which
will confuse the parser and cause the kernel to misbehave.

For example, "Zifencei" will be parsed as "ifc" since the parser will
fail at 'Z' and then continue at 'i'. Then, if we disable the FPU in
the CPU hardware and remove the "fd" from the device tree but leave
the CONFIG_FPU=y in the kernel, the kernel will panic at 
`__fstate_restore` function since the "Zifencei" (parsed as "ifc")
will confuse the current kernel that the CPU has "f", and the kernel
will save and restore the FPU registers during the context switch,
leading to illegal instruction exceptions.

However, it is not necessary to require the ISA string must be all
lowercase. The case-insensitive parser can be easily implemented
using `strncasecmp` and `tolower` functions. Moreover, the kernel
parser implementation should match the ISA specification rather than
using a more strict rule.

This patch series allows case-insensitive RISC-V ISA string:
* Patch 1 modifies the ISA string parser in the kernel to support
  case-insensitive ISA string parsing. It replaces `strncmp` with
  `strncasecmp`, replaces `islower` with `isalpha`, and wraps the
  dereferenced char in the parser with `tolower`.
* Patch 2 modifies the docs to no longer require the riscv,isa
  string to be all lowercase.

Yangyu Chen (2):
  riscv: allow case-insensitive ISA string parsing
  docs: dt: allow case-insensitive RISC-V ISA string

 .../devicetree/bindings/riscv/cpus.yaml       |  7 +++----
 arch/riscv/kernel/cpu.c                       |  6 ++++--
 arch/riscv/kernel/cpufeature.c                | 20 +++++++++----------
 3 files changed, 17 insertions(+), 16 deletions(-)

-- 
2.40.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ