Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1453718imm; Thu, 12 Jul 2018 02:04:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe6sEm/59uBD6kD9Bdz1DtD9Y1rOInpDNEX1UJiUqCWgsawXaRKBvpuO6mbWCd/wNMxm11l X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr1333249plb.293.1531386244467; Thu, 12 Jul 2018 02:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531386244; cv=none; d=google.com; s=arc-20160816; b=MJwFp3kZRsVHKm4pHG9ImYnYoZ1IZUpU+N9P9seqlBWouUdnndO8ZPPif6NRLUN6Lr phem+ZAt4/cQyFgbssP6HROUIcTRVsB0BOqa6ye2PFrQZ/OSpUVkBs8gkX5TmsBGpdsG bTIxfC/Y0JALR+uQdeRtpF4JbiFTEoKg9nDfK6uCrFQwUfCtUp3OiqAMbP/22dFzo4n9 BApcH3Sl/rZr++cR7W3q89e2RvWCn2cyuzqtmkQjSXBOGwtwcStL2mXnGb9no6clYvMq AmijjDYXiUaSIA9z5uNwaAlQmXnnVGJW0WtK9nwPkd16H55Zv39fog9OJU0WMF5Fi0N6 Idxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=YaHS3fa20mvkoVRI7l0uzliqKqjYEdHgj5srKj8agw4=; b=F5wn43cErmoaw6G0GuqbMtmgnMd6yuJ9Rpqh6vEaznJ8S0sVQb07VErj8nX48Cl9CY nvyvri/VOu5ZRKK9z5HSya5ZV8WqgvaLoMznK2oF4E2DGIgOoDumTw4RQNt3l/O0SUgI VTXqUW+Gr2x3o8UqtLMf4/lnsHyHr1G+C0BcipUjXFDl9/AJGuq/4bpLWUliv0Z6Fwe2 SwHR8DuUYQYyfU+Mbb4z2X/4KJ0QXna6OzXe6mKQe7y0FvkefJUKAnRdeVgEnbJ8VSi5 SXYE8cnaRp21X0WftYB07Wmxxrk5zJGzYex5amMY/Qbl2b2qfb6tHcXfYwQILsEJMFQ/ w+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TlTTF47U; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g67-v6si21591914plb.73.2018.07.12.02.03.46; Thu, 12 Jul 2018 02:04:04 -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=@gmail.com header.s=20161025 header.b=TlTTF47U; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbeGLJLt (ORCPT + 99 others); Thu, 12 Jul 2018 05:11:49 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:42067 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbeGLJLt (ORCPT ); Thu, 12 Jul 2018 05:11:49 -0400 Received: by mail-vk0-f68.google.com with SMTP id t4-v6so15844497vke.9; Thu, 12 Jul 2018 02:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=YaHS3fa20mvkoVRI7l0uzliqKqjYEdHgj5srKj8agw4=; b=TlTTF47UYs0/MRSUYfE0raHybmRWpI7aP1tj/NjpaYlyAPb27CJwuzYJUIgUhOC/Ps dE6TPPKBVd7Gqs4v+B3ngj3GUqzwfyCL8tASNvApND1bLJp2SCe+EXFT7IxIEit39aGn qHiIcqv4t4APqOAeXbA6x1bbjnrjiYH0XfKa3eKJn708mq/MomvshLurocSpU6xDHTqX cU6EYbemr0ofni6reejuxN/o2youSG5izJFB5YBbHQtkv+2NLAOa6u+rWwYGsTNYXD2o 3BJ0ns1Q+YAUjaU2Zzn/DNAwrRnL2Pi1d3ns3+0NmxS34E4ICkgq+ChAxZvAtWSU/V02 SLsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=YaHS3fa20mvkoVRI7l0uzliqKqjYEdHgj5srKj8agw4=; b=Qupkc59gqMNEvXknWj9BoBzjb8ZVMyCtodak/xS4WtDaWC+xJtOZ5b5FLPKgdn0dZ+ dStWhmgxC/JnuXA4NyyKh9/Qq6oXwS92Hh3EoXl9xPUKyG91lfJUoU66EKXN8gHSjGHA q7tw395WL3mZB+B79hB+i4/x72qzw8XaQArt7owuE0LQl2pwWxB68i47ZCM30UPpKQ7e b3Xb04tprdHHqby2qqlWnGDaEQ6W4UCagTNWplNA3kXLx4Zr+GOKvOidWM4uGdzW/dLL 8n4eH20hf0WrcAg34YevQ4RdXcN/V5Zt0tgLwJ+rfp6jXRtqjzhx2/TVL9d53O5EpyvA Sirw== X-Gm-Message-State: AOUpUlHQCg0A3nRqm+SuBF68m4x4y20sqCY/J0QK7MaQ0l/AcDrXqvlQ z2TZsfBdctGZUFfIAmJk+FMERRWGgi8jnXJWeFQXZg== X-Received: by 2002:a1f:20d4:: with SMTP id g203-v6mr697022vkg.176.1531386189349; Thu, 12 Jul 2018 02:03:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:2149:0:0:0:0:0 with HTTP; Thu, 12 Jul 2018 02:03:08 -0700 (PDT) In-Reply-To: <20180711160744.32074-1-tycho@tycho.ws> References: <20180706212220.GC3583@cisco.lan> <20180711160744.32074-1-tycho@tycho.ws> From: Andy Shevchenko Date: Thu, 12 Jul 2018 12:03:08 +0300 Message-ID: Subject: Re: [PATCH v4] uart: fix race between uart_put_char() and uart_shutdown() To: Tycho Andersen Cc: Greg Kroah-Hartman , Jiri Slaby , "open list:SERIAL DRIVERS" , Linux Kernel Mailing List , "Serge E . Hallyn" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- With Best Regards, Andy Shevchenko