Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1807549imm; Mon, 3 Sep 2018 09:58:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZXvCYQ/Nah5RglK40UYN9jeu5HBBVj+l4i0HtGe8K8YQVzPm0o+/7JJE58x02h7X2r42GY X-Received: by 2002:a62:d544:: with SMTP id d65-v6mr30347421pfg.107.1535993902024; Mon, 03 Sep 2018 09:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535993901; cv=none; d=google.com; s=arc-20160816; b=EvF9LqdG9nb4xULsHQEQYTvnrinPuZ4R9+fpjcXCW+QALEpklxTbIDUldPQ3LFjwMV Hcb/qXIb47ccsJWB+sFRRez+xLA9WrhLXkQBfIxZ3Q3RvNbVWT/ZmFLBGmAFh+lnkWXj qNfjGmWoPIkZARrx1yblq0VLOn9Gk1/w8AROXT8Nn+wA1Ebgum1bwmvcJW2nxKls3RVb A/817YJ+brPEGDeF2VUpVwJA5TMaodXwhkqNCn0d9kqEiiVNTdUYUs3khiCTrm7VsqST b35kh6GkteROxA/+nZgW6ivDh2BeFaLOl/PMjUxdBzQzMHuCIsPktQmIEKu/BZ93VgYh neqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=pr975JCzWCkcuM69evolnKQNNRXCXUiPHrsc4GObTkU=; b=CGb38b8C/0+g15v8nxec8LCH0NkSqD7TG5H5G3Na3msMlnCfmX+5+cERvHEjgm36pJ sC2MSw5x0xra55KbXABg3oBc9yNT9Eo7qmNj/ssu17JuU7iKDQ0QJvTUzKyrpnPA7bOu BQS/RtXurB6lIvOGrsFFl0Eg7Fof8Zfb++XcBnPVJaS7PYPX/Duuffwq1IzvmGokQLwA ny9NcSECPvk0AymNcgz9klbriGC2mwRoths47ZkfFp7QI/Lfz3vuTj1cJ8Fvlfe8odin FGqDsKmeSwBOP+jsgeq5ZTsNvlW56PCJYZas+GhGX4sjEVXFcr22eTJ8PWDYRpywKpft MBTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b="i/Pnqb5g"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si18300489plc.332.2018.09.03.09.58.07; Mon, 03 Sep 2018 09:58:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b="i/Pnqb5g"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728697AbeICVOD (ORCPT + 99 others); Mon, 3 Sep 2018 17:14:03 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:44685 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728654AbeICVOC (ORCPT ); Mon, 3 Sep 2018 17:14:02 -0400 Received: by mail-ed1-f66.google.com with SMTP id s10-v6so1218775edb.11 for ; Mon, 03 Sep 2018 09:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pr975JCzWCkcuM69evolnKQNNRXCXUiPHrsc4GObTkU=; b=i/Pnqb5gM9FdbghZSbLK0yE5jaqNNl33xCKN8uQ5wWMTMwuU/bf4EUjb3PPHrvjWD8 C/YVfhHjET6LUJugRpRVr4gHAqWrqenjbYgavHmSgilh4W1PqZJHDafO7riLwvJllNOh 0LCE1pn56LNKiG40nyiQhf/rxjCco4p4Y6pAvLrfdwowicoMU5gnGYzB2C6ZCvIRFKLk ttgyuHz86kBtl1amLS1n72JWlKczUbASWkhzv0cdqWLqHWN5gsMInDloLbq1BdyP9fCK UqoDP2ioFd3vh9etELO8/USeq44ZmcIBjx9ZrVzJ47pKuBKo7rqdD48ztqzorJ6xa338 mYBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pr975JCzWCkcuM69evolnKQNNRXCXUiPHrsc4GObTkU=; b=TNCF/ZZE+UpaJ2NV8Qk1hRAmCN1QW2jsD7Eiux6I9FEU3f+OTfaNwWRdQcmYmYHL5E DY22m02FSDO8BfDCJXugkTuq748j+615McOcCrHxJDKYksytv6hXgFRFfVxWySkyTxo5 6dnp9l4UIWZIS8WIRH79+qYLN4gPAAjv/R7y4CZQG7M/RZmtKT/t3R61lmW9rl5RQzAw 1o8lREc/zyqyCBqaA+sshf/PpOlx3vwap7XQnJvvLHOGQ4Rwnal/x0ypglTflWx3h4AH 1eUhAGRTAU4K7f8Teb+hWdDCX/+pR7gH1eRrORvjK2SMYJhvgI2ig8ioWlOL9I+UGsqs UVOg== X-Gm-Message-State: APzg51BCc3t6g5VHOuQ+q/EzVDUaAkBkxDVi7VFhHRT3Q2xbl/zh4ym1 mYrSUMqKzoL08+RJCAbr2mmSze+yO3Q= X-Received: by 2002:a50:9732:: with SMTP id c47-v6mr33345761edb.89.1535993584118; Mon, 03 Sep 2018 09:53:04 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m35-v6sm8085745ede.14.2018.09.03.09.53.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 09:53:03 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , Nathan March , =?UTF-8?q?Pasi=20K=C3=A4rkk=C3=A4inen?= , Peter Hurley , Sergey Senozhatsky , Tan Xiaojun , Tetsuo Handa , Greg Kroah-Hartman , Jiri Slaby Subject: [PATCHv2 3/4] tty/lockdep: Add ldisc_sem asserts Date: Mon, 3 Sep 2018 17:52:56 +0100 Message-Id: <20180903165257.29227-4-dima@arista.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180903165257.29227-1-dima@arista.com> References: <20180903165257.29227-1-dima@arista.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make sure under CONFIG_LOCKDEP that each change to line discipline is done with held write semaphor. Otherwise potential reader will have a good time dereferencing incomplete/uninitialized ldisc. Exception here is tty_ldisc_open(), as it's called without ldisc_sem locked by tty_init_dev() for the tty->link. Cc: Greg Kroah-Hartman Cc: Jiri Slaby Signed-off-by: Dmitry Safonov --- drivers/tty/tty_ldisc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index fc4c97cae01e..202cb645582f 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -471,6 +471,7 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) { + lockdep_assert_held(&tty->ldisc_sem); WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); clear_bit(TTY_LDISC_OPEN, &tty->flags); if (ld->ops->close) @@ -492,6 +493,7 @@ static int tty_ldisc_failto(struct tty_struct *tty, int ld) struct tty_ldisc *disc = tty_ldisc_get(tty, ld); int r; + lockdep_assert_held(&tty->ldisc_sem); if (IS_ERR(disc)) return PTR_ERR(disc); tty->ldisc = disc; @@ -615,6 +617,7 @@ EXPORT_SYMBOL_GPL(tty_set_ldisc); */ static void tty_ldisc_kill(struct tty_struct *tty) { + lockdep_assert_held(&tty->ldisc_sem); if (!tty->ldisc) return; /* @@ -662,6 +665,7 @@ int tty_ldisc_reinit(struct tty_struct *tty, int disc) struct tty_ldisc *ld; int retval; + lockdep_assert_held(&tty->ldisc_sem); ld = tty_ldisc_get(tty, disc); if (IS_ERR(ld)) { BUG_ON(disc == N_TTY); @@ -825,6 +829,7 @@ int tty_ldisc_init(struct tty_struct *tty) */ void tty_ldisc_deinit(struct tty_struct *tty) { + /* no ldisc_sem, tty is being destroyed */ if (tty->ldisc) tty_ldisc_put(tty->ldisc); tty->ldisc = NULL; -- 2.13.6