Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1965616ybg; Thu, 24 Oct 2019 02:57:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9wr+8ej4NmyOKilifK33YUi7dYfhecu6ag5exRSgoVDclDfOzYWOvElnmyr0gSph0PVNk X-Received: by 2002:a50:f783:: with SMTP id h3mr24171146edn.294.1571911040465; Thu, 24 Oct 2019 02:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571911040; cv=none; d=google.com; s=arc-20160816; b=O815hxxaV2rvQ+ptgM6orHl4Q2ATiLTsAamiKHrG6rO79SInAUc+6A4aFS+H5/Eq9j M61GU0q7hiqbgU5vnKB/lC0lAufg3kWbOWaR82gsR0MbiDiGSHFFfX45AlEt5ystwB35 Rivv3x68ac6d05QyQ5ov5wpSVvAoO3SfBeTAzysVguaZP8IsQpM26nGG+3iXqaaTygV5 I3FXX8HP9+tdVhL0LqwwL7mYuYOZ4lU/qSRR49DIo9ELBxBEDul+qQy8l7T1SPH9e60c FtIZF30y6gDLcbZHa47xAsKL71lnnw7UYdGkyA/2m6Co2MUa9YcPACP80Th+OylVhSBD J3AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=Pfelg5hi6R03mZ1vLzjmM92WqqQzhNWSQkGO0kPCCJs=; b=qGujrlgA0W/tmx4vPsIdTCTL0vovG+s2FPRSTuoQ1HwGqC284hDf3UK1Ddd3M39iPI eAfAXuxLl2WoDB7RlvOeF04GJbv4BNY25bCm5zbnQyW88Bf85EYHuXDB8QBdhvPkUBsP 73S07zH2GXxM9yyRajX6T3SpFSz8Gb6B8Yb/lVsHRYMl5uicW1OiXMxCGMSK8eC19y4q Akw1ievME0Tl33uQ9ZPZleGbgblFjLH+OJhWMfqen9LDJguFcCOmeLtbwfy6y8HhxOeJ YbjqL+l5dan7pBmNQyq9h5r1o5otBNClVftCg2pugy4bhxtGn7BwX12dsrw1ecXHPAUS 2fPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aMF3H5Iz; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si14623193ejk.158.2019.10.24.02.56.55; Thu, 24 Oct 2019 02:57:20 -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=@redhat.com header.s=mimecast20190719 header.b=aMF3H5Iz; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407488AbfJWUSr (ORCPT + 99 others); Wed, 23 Oct 2019 16:18:47 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43296 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2406050AbfJWUSq (ORCPT ); Wed, 23 Oct 2019 16:18:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571861925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pfelg5hi6R03mZ1vLzjmM92WqqQzhNWSQkGO0kPCCJs=; b=aMF3H5Izte9cm8ahEdm9eAAreVhSy7vK3LbSb8/FLtgZXXtKhQHI7He3ZPAPQGpm41AE+y 8GKylcpzZEjLEdjLmWF1SZ6PhPg3vU29+sonb+Lzp+NBXD6yF1fcyKWiaUVw2fus5CLwA3 k4OIPsnvmLu+H1tEjmJCSd6njY2xM/E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-15-jlueH4OLP0adVaz8-ap9CA-1; Wed, 23 Oct 2019 16:18:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04489100551A; Wed, 23 Oct 2019 20:18:40 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-40.rdu2.redhat.com [10.10.121.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F5615DC18; Wed, 23 Oct 2019 20:18:37 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [RFC PATCH 10/10] pipe: Check for ring full inside of the spinlock in pipe_write() [ver #2] From: David Howells To: torvalds@linux-foundation.org Cc: dhowells@redhat.com, Rasmus Villemoes , Greg Kroah-Hartman , Peter Zijlstra , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , dhowells@redhat.com, keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 23 Oct 2019 21:18:36 +0100 Message-ID: <157186191654.3995.6474781916564747415.stgit@warthog.procyon.org.uk> In-Reply-To: <157186182463.3995.13922458878706311997.stgit@warthog.procyon.org.uk> References: <157186182463.3995.13922458878706311997.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: jlueH4OLP0adVaz8-ap9CA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make pipe_write() check to see if the ring has become full between it taking the pipe mutex, checking the ring status and then taking the spinlock. This can happen if a notification is written into the pipe as that happens without the pipe mutex. Signed-off-by: David Howells --- fs/pipe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/pipe.c b/fs/pipe.c index 3df93990dd9d..6a982a88f658 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -462,6 +462,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) =09=09=09spin_lock_irq(&pipe->wait.lock); =20 =09=09=09head =3D pipe->head; +=09=09=09if (pipe_full(head, pipe->tail, max_usage)) { +=09=09=09=09spin_unlock_irq(&pipe->wait.lock); +=09=09=09=09continue; +=09=09=09} + =09=09=09pipe_commit_write(pipe, head + 1); =20 =09=09=09/* Always wake up, even if the copy fails. Otherwise