Received: by 2002:a17:90a:37e8:0:0:0:0 with SMTP id v95csp4218630pjb; Mon, 21 Oct 2019 01:56:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzKdOT8K+ZqWCOQ9y+93ZNNXESe3WIA9lRoTnQSic6EWDPJq/6y24auyiUVqGIg1VKwYtz X-Received: by 2002:aa7:df86:: with SMTP id b6mr23533908edy.107.1571648217826; Mon, 21 Oct 2019 01:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571648217; cv=none; d=google.com; s=arc-20160816; b=QtivNrIHxFY6Ok/4wzIFdpQP9TAqLwnpLWRXqCIHB8/e+nT4Vp2W0PEF2802Xzj+Eb MB5d/nnuHdWqCJYFjg4e/TWr4hPrwiqaDHPnLyc9ZMQ35rto2FAQY6jQyehjhq2wglmY OO0xVuWN+GNbCWsg2IHBxEc2/TLd1POkBvLG1NeUyR4urtmQpWl+ZB8p3XDm0n9OcpN9 1/8v8jfau2PT0nAZi0MH6hsrBnoh/BHclGurwTirPTvPt3+TNcJmml2MWiT1KHi8PHM7 RqN3jjVdeNunnFfqCHP9D4+lBWsBnEML0tZwVcX2s1TYIUuY80X1bEMFBqxmcPa/0H0X W7Ow== 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; bh=+TVhX0pj0cp6PSiJ52MPNmOFMdXEiWzFfisANukiR/A=; b=ZSiXeyshfBNv7jvhrRtLLpe575J4kB3Bqpr+KU3jPNCc+f2EX1XUnwdWvweAWzcHBt sa29xfBZar3nu7HxSbIDSNdVwrAi318llBU+kE9Pxbp3kerOgjK6pJ6Z8N3VlxhzYaLs NE81S9GvhZx0h//QUbM/YbrExpsCrv4fiitxlSgUHQCT92LuTCvot7A28n0ROoDnCkWT Aw2jGMP7CJ06vDuBbnu7YOSxJLEeev1k09XgjU06D56AoBGYiSxa9NEgMnQEbXPJD7Kd e0iZoi5P5q4JPdtcEoMS2I+6yHbLZ5TVKWWK1A3oWb9mlu0NiWdHr4rejexiZPm9D7aK LhrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y26si8992467edv.134.2019.10.21.01.56.34; Mon, 21 Oct 2019 01:56:57 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727130AbfJUI4T (ORCPT + 99 others); Mon, 21 Oct 2019 04:56:19 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46113 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbfJUI4S (ORCPT ); Mon, 21 Oct 2019 04:56:18 -0400 Received: by mail-lf1-f65.google.com with SMTP id t8so9382639lfc.13; Mon, 21 Oct 2019 01:56:15 -0700 (PDT) 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=+TVhX0pj0cp6PSiJ52MPNmOFMdXEiWzFfisANukiR/A=; b=PzJcr1STgaFqPo9lnBj1xDOoCdd+IaDmTpZKkGoE62joTo/L8d81vrXVGmofFj6Uot nvp3OidK/Hia42ZnzZ9FcDr3sqXCTF/UbXSYxeoEBNoENocg0xBQRAJEB042NJ7kIiTK Kv/uPuW9HWC8FmnYVLN4UGwVqn8HLSzg348y+ZoZrxFJv3UsgnXhQ8m9cBukaSN7G344 fy4w6oP4OkIi7jStuWCNqU+tpiW6xBNvukPr5L5gLlkMNxSO9ekYNlanx5mM9cPCpnxn ugGkKXKVBpu7gSXq6xuwZb4dadO3IlcHLMSmFVbzVJ3ePweviIjWBbPTcDG4SzwX8oHt mvnA== X-Gm-Message-State: APjAAAUOW2F06NiP0FHmTS4Kdy0dmvHRmCkoA1eybGhcfGf/yEkx6ECB mMISpTFg2nYWG/nmWB5JNOsgUXiq X-Received: by 2002:a19:e018:: with SMTP id x24mr12198432lfg.191.1571648175037; Mon, 21 Oct 2019 01:56:15 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id c22sm453212lfj.28.2019.10.21.01.56.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 01:56:14 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iMTUJ-0008Gb-3L; Mon, 21 Oct 2019 10:56:27 +0200 Date: Mon, 21 Oct 2019 10:56:27 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Johan Hovold , Alan Stern , Oliver Neukum , "Paul E . McKenney" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable Subject: Re: [PATCH RFC v2 2/2] USB: ldusb: fix ring-buffer locking Message-ID: <20191021085627.GD24768@localhost> References: <20191018151955.25135-1-johan@kernel.org> <20191018151955.25135-3-johan@kernel.org> <20191018185458.GA1191145@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191018185458.GA1191145@kroah.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 18, 2019 at 11:54:58AM -0700, Greg Kroah-Hartman wrote: > On Fri, Oct 18, 2019 at 05:19:55PM +0200, Johan Hovold wrote: > > The custom ring-buffer implementation was merged without any locking > > whatsoever, but a spinlock was later added by commit 9d33efd9a791 > > ("USB: ldusb bugfix"). > > > > The lock did not cover the loads from the ring-buffer entry after > > determining the buffer was non-empty, nor the update of the tail index > > once the entry had been processed. The former could lead to stale data > > being returned, while the latter could lead to memory corruption on > > sufficiently weakly ordered architectures. > > Ugh. > > This almost looks sane, but what's the odds there is some other issue in > here as well? Would it make sense to just convert the code to use the > "standard" ring buffer code instead? Yeah, long term that may be the right thing to do, but I wanted a minimal fix addressing the issue at hand without having to reimplement the driver and fix all other (less-critical) issues in there... For the ring-buffer corruption / info-leak issue, these two patches should be sufficient though. Copying the ring-buffer entry to a temporary buffer while holding the lock might still be preferred to avoid having to deal with barrier subtleties. But unless someone speaks out against 2/2, I'd just go ahead and apply it. Johan