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: <20230914183831.587273-1-john.ogness@linutronix.de>
Date:   Thu, 14 Sep 2023 20:43:17 +0206
From:   John Ogness <john.ogness@...utronix.de>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     Jiri Slaby <jirislaby@...nel.org>, linux-serial@...r.kernel.org,
        Petr Mladek <pmladek@...e.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, Tobias Klauser <tklauser@...tanz.ch>,
        Thierry Reding <treding@...dia.com>,
        Joel Stanley <joel@....id.au>,
        Andrew Jeffery <andrew@...id.au>,
        linux-arm-kernel@...ts.infradead.org,
        linux-aspeed@...ts.ozlabs.org, Al Cooper <alcooperx@...il.com>,
        Broadcom internal kernel review list 
        <bcm-kernel-feedback-list@...adcom.com>,
        Tony Lindgren <tony@...mide.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
        Florian Fainelli <f.fainelli@...il.com>,
        Andrew Davis <afd@...com>,
        Matthew Howell <matthew.howell@...level.com>,
        Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>, Johan Hovold <johan@...nel.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>,
        Chen-Yu Tsai <wenst@...omium.org>,
        linux-mediatek@...ts.infradead.org, Lukas Wunner <lukas@...ner.de>,
        Matthias Schiffer <matthias.schiffer@...tq-group.com>,
        Arnd Bergmann <arnd@...db.de>,
        Kumaravel Thiagarajan <kumaravel.thiagarajan@...rochip.com>,
        Tharun Kumar P <tharunkumar.pasumarthi@...rochip.com>,
        Russell King <linux@...linux.org.uk>,
        "Maciej W. Rozycki" <macro@...am.me.uk>,
        Hongyu Xie <xiehongyu1@...inos.cn>,
        Jiamei Xie <jiamei.xie@....com>, Rob Herring <robh@...nel.org>,
        delisun <delisun@...eo.com.cn>,
        Lino Sanfilippo <l.sanfilippo@...bus.com>,
        Yangtao Li <frank.li@...o.com>,
        Vineet Gupta <vgupta@...nel.org>,
        linux-snps-arc@...ts.infradead.org,
        Richard Genoud <richard.genoud@...il.com>,
        Nicolas Ferre <nicolas.ferre@...rochip.com>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Claudiu Beznea <claudiu.beznea@...on.dev>,
        Arend van Spriel <arend.vanspriel@...adcom.com>,
        Christophe Leroy <christophe.leroy@...roup.eu>,
        Baruch Siach <baruch@...s.co.il>,
        Sherry Sun <sherry.sun@....com>,
        Shenwei Wang <shenwei.wang@....com>,
        Shawn Guo <shawnguo@...nel.org>,
        Sascha Hauer <s.hauer@...gutronix.de>,
        Pengutronix Kernel Team <kernel@...gutronix.de>,
        Fabio Estevam <festevam@...il.com>,
        NXP Linux Team <linux-imx@....com>,
        Sergey Organov <sorganov@...il.com>, Tom Rix <trix@...hat.com>,
        Marek Vasut <marex@...x.de>,
        Karol Gugala <kgugala@...micro.com>,
        Mateusz Holenko <mholenko@...micro.com>,
        Gabriel Somlo <gsomlo@...il.com>,
        Vladimir Zapolskiy <vz@...ia.com>,
        Jacky Huang <ychuang3@...oton.com>,
        Shan-Chun Hung <schung@...oton.com>,
        Neil Armstrong <neil.armstrong@...aro.org>,
        Kevin Hilman <khilman@...libre.com>,
        Jerome Brunet <jbrunet@...libre.com>,
        Martin Blumenstingl <martin.blumenstingl@...glemail.com>,
        Dmitry Rokosov <ddrokosov@...rdevices.ru>,
        Lucas Tanure <tanure@...ux.com>,
        linux-amlogic@...ts.infradead.org,
        Taichi Sugaya <sugaya.taichi@...ionext.com>,
        Takao Orito <orito.takao@...ionext.com>,
        Liviu Dudau <liviu.dudau@....com>,
        Sudeep Holla <sudeep.holla@....com>,
        Lorenzo Pieralisi <lpieralisi@...nel.org>,
        Andy Gross <agross@...nel.org>,
        Bjorn Andersson <andersson@...nel.org>,
        Konrad Dybcio <konrad.dybcio@...aro.org>,
        linux-arm-msm@...r.kernel.org,
        Pali Rohár <pali@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andreas Färber <afaerber@...e.de>,
        Manivannan Sadhasivam <mani@...nel.org>,
        linux-actions@...ts.infradead.org,
        Xiongfeng Wang <wangxiongfeng2@...wei.com>,
        Yuan Can <yuancan@...wei.com>,
        Michael Ellerman <mpe@...erman.id.au>,
        Nicholas Piggin <npiggin@...il.com>,
        linuxppc-dev@...ts.ozlabs.org, linux-unisoc@...ts.infradead.org,
        Kevin Cernekee <cernekee@...il.com>,
        Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>,
        Alim Akhtar <alim.akhtar@...sung.com>,
        linux-samsung-soc@...r.kernel.org,
        Lukas Bulwahn <lukas.bulwahn@...il.com>,
        Lech Perczak <lech.perczak@...lingroup.com>,
        Hugo Villeneuve <hvilleneuve@...onoff.com>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Isaac True <isaac.true@...onical.com>,
        Laxman Dewangan <ldewangan@...dia.com>,
        Thierry Reding <thierry.reding@...il.com>,
        Jonathan Hunter <jonathanh@...dia.com>,
        linux-tegra@...r.kernel.org, Biju Das <biju.das.jz@...renesas.com>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        Palmer Dabbelt <palmer@...belt.com>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Nick Hu <nick.hu@...ive.com>,
        Ruan Jinjie <ruanjinjie@...wei.com>,
        Samuel Holland <samuel.holland@...ive.com>,
        linux-riscv@...ts.infradead.org, Orson Zhai <orsonzhai@...il.com>,
        Baolin Wang <baolin.wang@...ux.alibaba.com>,
        Chunyan Zhang <zhang.lyra@...il.com>,
        Patrice Chotard <patrice.chotard@...s.st.com>,
        Maxime Coquelin <mcoquelin.stm32@...il.com>,
        Alexandre Torgue <alexandre.torgue@...s.st.com>,
        Valentin Caron <valentin.caron@...s.st.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        linux-stm32@...md-mailman.stormreply.com,
        "David S. Miller" <davem@...emloft.net>,
        sparclinux@...r.kernel.org, Hammer Hsieh <hammerh0314@...il.com>,
        Peter Korsgaard <jacmet@...site.dk>,
        Timur Tabi <timur@...nel.org>,
        Mukesh Ojha <quic_mojha@...cinc.com>,
        Jonathan Neuschäfer <j.neuschaefer@....net>,
        Michal Simek <michal.simek@....com>
Subject: [PATCH tty v1 00/74] serial: wrappers for uart port lock

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

Provide and use wrapper functions for spin_[un]lock*(port->lock)
invocations so that the console mechanics can be applied later on at a
single place and does not require to copy the same logic all over the
drivers.

Patch 1 adds the wrapper functions.

Patches 2-74 switch all uart port locking call sites to use the new
wrappers. These patches were automatically generated using coccinelle.
The 2 used coccinelle scripts are included below and executed as
follows:

$ spatch --sp-file uartlock-1.cocci $FILE
$ spatch --sp-file uartlock-2.cocci --recursive-includes $FILE

This series brings no functional change.

Patches 2-74 contain identical commit message bodies. Feel free to
fold them into a single commit if that seems more reasonable.

Thomas Gleixner (74):
  serial: core: Provide port lock wrappers
  serial: core: Use lock wrappers
  serial: 21285: Use port lock wrappers
  serial: 8250_aspeed_vuart: Use port lock wrappers
  serial: 8250_bcm7271: Use port lock wrappers
  serial: 8250: Use port lock wrappers
  serial: 8250_dma: Use port lock wrappers
  serial: 8250_dw: Use port lock wrappers
  serial: 8250_exar: Use port lock wrappers
  serial: 8250_fsl: Use port lock wrappers
  serial: 8250_mtk: Use port lock wrappers
  serial: 8250_omap: Use port lock wrappers
  serial: 8250_pci1xxxx: Use port lock wrappers
  serial: altera_jtaguart: Use port lock wrappers
  serial: altera_uart: Use port lock wrappers
  serial: amba-pl010: Use port lock wrappers
  serial: amba-pl011: Use port lock wrappers
  serial: apb: Use port lock wrappers
  serial: ar933x: Use port lock wrappers
  serial: arc_uart: Use port lock wrappers
  serial: atmel: Use port lock wrappers
  serial: bcm63xx-uart: Use port lock wrappers
  serial: cpm_uart: Use port lock wrappers
  serial: digicolor: Use port lock wrappers
  serial: dz: Use port lock wrappers
  serial: linflexuart: Use port lock wrappers
  serial: fsl_lpuart: Use port lock wrappers
  serial: icom: Use port lock wrappers
  serial: imx: Use port lock wrappers
  serial: ip22zilog: Use port lock wrappers
  serial: jsm: Use port lock wrappers
  serial: liteuart: Use port lock wrappers
  serial: lpc32xx_hs: Use port lock wrappers
  serial: ma35d1: Use port lock wrappers
  serial: mcf: Use port lock wrappers
  serial: men_z135_uart: Use port lock wrappers
  serial: meson: Use port lock wrappers
  serial: milbeaut_usio: Use port lock wrappers
  serial: mpc52xx: Use port lock wrappers
  serial: mps2-uart: Use port lock wrappers
  serial: msm: Use port lock wrappers
  serial: mvebu-uart: Use port lock wrappers
  serial: omap: Use port lock wrappers
  serial: owl: Use port lock wrappers
  serial: pch: Use port lock wrappers
  serial: pic32: Use port lock wrappers
  serial: pmac_zilog: Use port lock wrappers
  serial: pxa: Use port lock wrappers
  serial: qcom-geni: Use port lock wrappers
  serial: rda: Use port lock wrappers
  serial: rp2: Use port lock wrappers
  serial: sa1100: Use port lock wrappers
  serial: samsung_tty: Use port lock wrappers
  serial: sb1250-duart: Use port lock wrappers
  serial: sc16is7xx: Use port lock wrappers
  serial: tegra: Use port lock wrappers
  serial: core: Use port lock wrappers
  serial: mctrl_gpio: Use port lock wrappers
  serial: txx9: Use port lock wrappers
  serial: sh-sci: Use port lock wrappers
  serial: sifive: Use port lock wrappers
  serial: sprd: Use port lock wrappers
  serial: st-asc: Use port lock wrappers
  serial: stm32: Use port lock wrappers
  serial: sunhv: Use port lock wrappers
  serial: sunplus-uart: Use port lock wrappers
  serial: sunsab: Use port lock wrappers
  serial: sunsu: Use port lock wrappers
  serial: sunzilog: Use port lock wrappers
  serial: timbuart: Use port lock wrappers
  serial: uartlite: Use port lock wrappers
  serial: ucc_uart: Use port lock wrappers
  serial: vt8500: Use port lock wrappers
  serial: xilinx_uartps: Use port lock wrappers

 drivers/tty/serial/21285.c                  |   8 +-
 drivers/tty/serial/8250/8250_aspeed_vuart.c |   6 +-
 drivers/tty/serial/8250/8250_bcm7271.c      |  28 +++---
 drivers/tty/serial/8250/8250_core.c         |  12 +--
 drivers/tty/serial/8250/8250_dma.c          |   8 +-
 drivers/tty/serial/8250/8250_dw.c           |   8 +-
 drivers/tty/serial/8250/8250_exar.c         |   4 +-
 drivers/tty/serial/8250/8250_fsl.c          |   6 +-
 drivers/tty/serial/8250/8250_mtk.c          |   8 +-
 drivers/tty/serial/8250/8250_omap.c         |  52 +++++-----
 drivers/tty/serial/8250/8250_pci1xxxx.c     |   8 +-
 drivers/tty/serial/8250/8250_port.c         | 100 ++++++++++----------
 drivers/tty/serial/altera_jtaguart.c        |  28 +++---
 drivers/tty/serial/altera_uart.c            |  20 ++--
 drivers/tty/serial/amba-pl010.c             |  20 ++--
 drivers/tty/serial/amba-pl011.c             |  72 +++++++-------
 drivers/tty/serial/apbuart.c                |   8 +-
 drivers/tty/serial/ar933x_uart.c            |  26 ++---
 drivers/tty/serial/arc_uart.c               |  16 ++--
 drivers/tty/serial/atmel_serial.c           |  24 ++---
 drivers/tty/serial/bcm63xx_uart.c           |  22 ++---
 drivers/tty/serial/cpm_uart.c               |   8 +-
 drivers/tty/serial/digicolor-usart.c        |  18 ++--
 drivers/tty/serial/dz.c                     |  32 +++----
 drivers/tty/serial/fsl_linflexuart.c        |  26 ++---
 drivers/tty/serial/fsl_lpuart.c             |  88 ++++++++---------
 drivers/tty/serial/icom.c                   |  26 ++---
 drivers/tty/serial/imx.c                    |  84 ++++++++--------
 drivers/tty/serial/ip22zilog.c              |  36 +++----
 drivers/tty/serial/jsm/jsm_neo.c            |   4 +-
 drivers/tty/serial/jsm/jsm_tty.c            |  16 ++--
 drivers/tty/serial/liteuart.c               |  20 ++--
 drivers/tty/serial/lpc32xx_hs.c             |  26 ++---
 drivers/tty/serial/ma35d1_serial.c          |  22 ++---
 drivers/tty/serial/mcf.c                    |  20 ++--
 drivers/tty/serial/men_z135_uart.c          |   8 +-
 drivers/tty/serial/meson_uart.c             |  30 +++---
 drivers/tty/serial/milbeaut_usio.c          |  16 ++--
 drivers/tty/serial/mpc52xx_uart.c           |  12 +--
 drivers/tty/serial/mps2-uart.c              |  16 ++--
 drivers/tty/serial/msm_serial.c             |  38 ++++----
 drivers/tty/serial/mvebu-uart.c             |  18 ++--
 drivers/tty/serial/omap-serial.c            |  38 ++++----
 drivers/tty/serial/owl-uart.c               |  26 ++---
 drivers/tty/serial/pch_uart.c               |  10 +-
 drivers/tty/serial/pic32_uart.c             |  20 ++--
 drivers/tty/serial/pmac_zilog.c             |  52 +++++-----
 drivers/tty/serial/pxa.c                    |  30 +++---
 drivers/tty/serial/qcom_geni_serial.c       |   8 +-
 drivers/tty/serial/rda-uart.c               |  34 +++----
 drivers/tty/serial/rp2.c                    |  20 ++--
 drivers/tty/serial/sa1100.c                 |  20 ++--
 drivers/tty/serial/samsung_tty.c            |  50 +++++-----
 drivers/tty/serial/sb1250-duart.c           |  12 +--
 drivers/tty/serial/sc16is7xx.c              |  40 ++++----
 drivers/tty/serial/serial-tegra.c           |  32 +++----
 drivers/tty/serial/serial_core.c            |  88 ++++++++---------
 drivers/tty/serial/serial_mctrl_gpio.c      |   4 +-
 drivers/tty/serial/serial_port.c            |   4 +-
 drivers/tty/serial/serial_txx9.c            |  26 ++---
 drivers/tty/serial/sh-sci.c                 |  68 ++++++-------
 drivers/tty/serial/sifive.c                 |  16 ++--
 drivers/tty/serial/sprd_serial.c            |  30 +++---
 drivers/tty/serial/st-asc.c                 |  18 ++--
 drivers/tty/serial/stm32-usart.c            |  38 ++++----
 drivers/tty/serial/sunhv.c                  |  28 +++---
 drivers/tty/serial/sunplus-uart.c           |  26 ++---
 drivers/tty/serial/sunsab.c                 |  34 +++----
 drivers/tty/serial/sunsu.c                  |  46 ++++-----
 drivers/tty/serial/sunzilog.c               |  42 ++++----
 drivers/tty/serial/timbuart.c               |   8 +-
 drivers/tty/serial/uartlite.c               |  18 ++--
 drivers/tty/serial/ucc_uart.c               |   4 +-
 drivers/tty/serial/vt8500_serial.c          |   8 +-
 drivers/tty/serial/xilinx_uartps.c          |  56 +++++------
 include/linux/serial_core.h                 |  91 ++++++++++++++++--
 76 files changed, 1086 insertions(+), 1007 deletions(-)


base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
-- 
2.39.2

--------------8<--------------
// uartlock-1.cocci

@r1@
struct uart_port *U;
@@

-spin_lock(&U->lock)
+uart_port_lock(U)

@r2@
struct uart_port *U;
@@

-spin_lock_irq(&U->lock)
+uart_port_lock_irq(U)

@r3@
struct uart_port *U;
identifier F;
@@

-spin_lock_irqsave(&U->lock, F)
+uart_port_lock_irqsave(U, &F)

@r4@
struct uart_port *U;
@@

-spin_unlock(&U->lock)
+uart_port_unlock(U)

@r5@
struct uart_port *U;
@@

-spin_unlock_irq(&U->lock)
+uart_port_unlock_irq(U)

@r6@
struct uart_port *U;
identifier F;
@@

-spin_unlock_irqrestore(&U->lock, F)
+uart_port_unlock_irqrestore(U, F)

@r7@
struct uart_port *U;
@@

-spin_trylock(&U->lock)
+uart_port_trylock(U)

@r8@
struct uart_port *U;
identifier F;
@@

-spin_trylock_irqsave(&U->lock, F)
+uart_port_trylock_irqsave(U, &F)

--------------8<--------------
// uartlock-2.cocci

@r10@
type T1;
identifier U;
@@

T1 {
   ...
   struct uart_port U;
   ...
};

@r11@
r10.T1 *E;
identifier r10.U;
@@

-spin_lock(&E->U.lock)
+uart_port_lock(&E->U)

@r12@
r10.T1 *E;
identifier r10.U;
@@

-spin_lock_irq(&E->U.lock)
+uart_port_lock_irq(&E->U)

@r13@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_lock_irqsave(&E->U.lock, F)
+uart_port_lock_irqsave(&E->U, &F)

@r14@
r10.T1 *E;
identifier r10.U;
@@

-spin_unlock(&E->U.lock)
+uart_port_unlock(&E->U)

@r15@
r10.T1 *E;
identifier r10.U;
@@

-spin_unlock_irq(&E->U.lock)
+uart_port_unlock_irq(&E->U)

@r16@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_unlock_irqrestore(&E->U.lock, F)
+uart_port_unlock_irqrestore(&E->U, F)

@r17@
r10.T1 *E;
identifier r10.U;
@@

-spin_trylock(&E->U.lock)
+uart_port_trylock(&E->U)

@r18@
r10.T1 *E;
identifier r10.U;
identifier F;
@@

-spin_trylock_irqsave(&E->U.lock, F)
+uart_port_trylock_irqsave(&E->U, &F)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ