Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1748431imm; Thu, 12 Jul 2018 07:14:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpegeWG2zwIwr2N+e/Q3DSu6r1mia2lPgEUdqjnHL/+BCidNT9arK7R7+m+MeL28mPrwC2Tx X-Received: by 2002:a63:1350:: with SMTP id 16-v6mr2309420pgt.214.1531404858347; Thu, 12 Jul 2018 07:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531404858; cv=none; d=google.com; s=arc-20160816; b=BlXZ0gOedPHf/K3Zgh3xB5qBrmT4jjTrLxcD4jmr0UuANTG3CVUdFVD1T+VX4Ll7z1 holIsgeWFfyh32mmzk3EAGX/nYJ7yGlpmTSc15m/0L+Gh9MdZjROfnMqDJvH12jw+4/S 56LsetS+6GC1AQ5AyXDg7a6k57vupv63/m4EWUNh/iyYNxtw6TVsqPoyb1+Jb6/fOVDh fk24Z68XQFwMCQd+F2KddFP9lk6nGwZTRtwHbwKNQFXfrwt4uu/U70ACSGn0OET0+ZSg 8yQNYzGQZxnNGboWdOrhxITQk4m+CiW/RIdIxMLkZlk4Qyc4rhAFsEHkyY0mPBA1rkx7 B0hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=c6e5mv5qZbiMykO/PA+TCD2xH5BtimFkI3u0CakJflw=; b=hDksmF2pFudlCodQgFTD/zwVttdgSeIhamcXy6HPEgGjAZyl6/HKa2i5wNH3pQXDuM cdzNzf4n0+ALRflQTty22YxertFtaA5MXoJOxx+QFgvKGX67DS74+M8UMhQxMoBdOEnF RdisVWwJ8Q4gF1Y0axzRu9mZwU+k/nal5rUi75OajyC8EAOvXUFK5bvxM0oeNUiNdOdA dS/MZPjDmfDmy4wzXEjsSsGOxg2n3MoplC0cwbFn5h1El7c9LmtwjjAFmvQAWSoLqcle YOvbLvaU8muYYjm0lTN79cJkXmalKwXtFF5TRe425YGEfp80d1Mvko+p3lkq9sqtQG8W U2KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=e+2Kje6r; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si24540066pfb.131.2018.07.12.07.14.02; Thu, 12 Jul 2018 07:14:18 -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=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=e+2Kje6r; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732302AbeGLOXD (ORCPT + 99 others); Thu, 12 Jul 2018 10:23:03 -0400 Received: from mail-qt0-f171.google.com ([209.85.216.171]:45501 "EHLO mail-qt0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbeGLOXD (ORCPT ); Thu, 12 Jul 2018 10:23:03 -0400 Received: by mail-qt0-f171.google.com with SMTP id y5-v6so24155234qti.12 for ; Thu, 12 Jul 2018 07:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=c6e5mv5qZbiMykO/PA+TCD2xH5BtimFkI3u0CakJflw=; b=e+2Kje6rk9ydoXyJ0AgIX6ccVNlw2yGeqreC40agwvm8iEYEp6G9U2pGbvP3C0yLTJ twjWzKZ+9ZbS6y9JdgeqoDe3SXuwu5a3rKHNdFvXkirHHvwNNdlmvkaJEZp0uTXhqlZU QcfLwmp2h5y0ixePMSgY4LHvFMSlqYCcBPe4Qd2+i+T42Lzxew50QOaV8DHtZpwFXb2c 7S4rF/9zZC9veWdEpdWNtsFWb8aXCe7mtftcGdtqKwd4f53RSOAZ9dY5bmpy2tbxDpho cl0xv8di3VX5jTEFFXXVW/0TRjBjDek63LvVPa4U78ntAQZ3GmnvKxmdoGyz/Je0uL72 iDqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=c6e5mv5qZbiMykO/PA+TCD2xH5BtimFkI3u0CakJflw=; b=NUFIAE2JlgvQk9t8I5AGkBYVz6AMXpqiEG372caWGrLPw2P3c2RUsEeqAAUVaiV4Yb xPSwSJvmgk7Y/OvbI0Wzc2WysStCZfqTDA28auDccTYM0rWYXLBaPyVYS1UM8JlVxMiA W5uetuBu6KM6HkJvV0LEemg9xdojuf2B0vFrDD01ZSziu/dWpoAnbdQ/jQQi/MQwyQ1F e/P+gHyTJSIQL2gOIntjv15PGURaLTglysrB5MWkd77iA1ohQN6PupeIzNqLGHwGSryx YAO/eXZ27eiiFPb3oldg42rGS8lHjVDKq2C6diK3z30YitoDe463p7ow1GH5uGR0Y6HZ ioZA== X-Gm-Message-State: AOUpUlF9Zkx/MJ5RlU87/53zGKOlcIoevA6WDJo8AJfuaXhJzMresjNs 85inL1fWb/Gj0aWENIMlOhRtO8h6 X-Received: by 2002:a0c:a9c4:: with SMTP id c4-v6mr2526396qvb.119.1531404797207; Thu, 12 Jul 2018 07:13:17 -0700 (PDT) Received: from cisco.cisco.com ([8.24.24.129]) by smtp.gmail.com with ESMTPSA id f2-v6sm4671085qkm.51.2018.07.12.07.13.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Jul 2018 07:13:16 -0700 (PDT) Date: Thu, 12 Jul 2018 08:13:14 -0600 From: Tycho Andersen To: Andy Shevchenko Cc: Greg Kroah-Hartman , Jiri Slaby , "open list:SERIAL DRIVERS" , Linux Kernel Mailing List , "Serge E . Hallyn" Subject: Re: [PATCH v4] uart: fix race between uart_put_char() and uart_shutdown() Message-ID: <20180712141314.GB13192@cisco.cisco.com> References: <20180706212220.GC3583@cisco.lan> <20180711160744.32074-1-tycho@tycho.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Thu, Jul 12, 2018 at 12:03:08PM +0300, Andy Shevchenko wrote: > On Wed, Jul 11, 2018 at 7:07 PM, Tycho Andersen wrote: > > > Anyway, since the lock is not acquired, if uart_shutdown() is called, the > > last chunk of that function may release state->xmit.buf before its assigned > > to null, and cause the race above. > > > > To fix it, let's lock uport->lock when allocating/deallocating > > state->xmit.buf in addition to the per-port mutex. > > > * use the result of uart_port_lock() in uart_shutdown() to avoid > > uninitialized warning > > * don't use the uart_port_lock/unlock macros in uart_port_startup, > > instead test against uport directly; the compiler can't seem to "see" > > through the macros/ref/unref calls to not warn about uninitialized > > flags. We don't need to do a ref here since we hold the per-port > > mutex anyway. > > > + if (uport) > > + spin_lock_irqsave(&uport->lock, flags); > > > + if (uport) > > + spin_unlock_irqrestore(&uport->lock, flags); > > At some point it It was uart_port_lock()/uart_port_unlock(), and you > changed to simple spin lock. The macro also take reference to the > port. Do we aware about that here? I don't think so, the commit message you quoted above says, > We don't need to do a ref here since we hold the per-port mutex > anyway. Cheers, Tycho