Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6904823ybp; Wed, 16 Oct 2019 00:21:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzR0934Ecw3yYCLbpS2gJf6FjwX5gxEGZ4dvE9hMl7CrTO/TIPylLTkXwjVZiYDaYgKhsXo X-Received: by 2002:aa7:db59:: with SMTP id n25mr14626073edt.288.1571210510741; Wed, 16 Oct 2019 00:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571210510; cv=none; d=google.com; s=arc-20160816; b=gX/e2K6uuyQ2xZmZHX5qcsJlLG9qkR5rCQL0bep97EERYj9b7XVhnMfKYzP09KvcDY DKx13oxfWDqB561s/YzI3l2sK17fmMfAtdGofDxjhqUXIM6A8mHIxN4pwZtE7CDBztV4 ys9LN6ksPJrR+mzrUQqsj/WRBpVv50HD47XZ1lUWs9d8caHBA7r+iLaGvhhZbp6SlgqM Dj/SsyjFSdUnCMaWevwZ0GnBFvn3I91sFc0YrBYW34hRk+I1tBVgi1Y0V4VUNlf0ZpuL bDttzM5keZ1XimLLNhG6TrJQgZAZvDgth7GfHG6vpjxcpvV5pXdQ0PkLkj7XbQGGoSHg n7DA== 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; bh=aql11Q+bF1ktGYH0wKzH+IqJOOYc6bmQ/wYHMrSkCc0=; b=i2pSzKWyXN6NH446mYUB2yPpBEUdxfi42z2m6YJsG1Si3bZVn2wx9sgcxJr3GhmGfm HNyG+biLI0p4HZvTH54Tx6Fnw8Y5Q7ecUy6zFSrrJ8uB63fpTM5C3oo//yA8Hm4HCoxp FMj9IsjZL0hoIod1+jssLK0fXoKwP2Y1zANXhZzRcBRG8zkxoL+h82Ix9oFq8FlsHTok PCvXW2EnZQMFid3cAmSzPSkrQWIHUAGXGaIqtNCwnoZR2KCzH1qBcD2btLyFLSctOB8t 8TKG6DWDDZtfiOC0aV/sDpYPTYTOMbeo4sL1NPeeX0dWtPiycaV2unISyRPyAp6cB1SZ +Rzw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si14766394ejr.180.2019.10.16.00.21.27; Wed, 16 Oct 2019 00:21:50 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388343AbfJOVtH (ORCPT + 99 others); Tue, 15 Oct 2019 17:49:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46642 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731008AbfJOVtE (ORCPT ); Tue, 15 Oct 2019 17:49:04 -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 mx1.redhat.com (Postfix) with ESMTPS id 725222CE90A; Tue, 15 Oct 2019 21:49:04 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-84.rdu2.redhat.com [10.10.121.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A535D9E2; Tue, 15 Oct 2019 21:49:01 +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 08/21] pipe: Check for ring full inside of the spinlock in pipe_write() From: David Howells To: torvalds@linux-foundation.org Cc: dhowells@redhat.com, Casey Schaufler , Stephen Smalley , Greg Kroah-Hartman , 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: Tue, 15 Oct 2019 22:49:01 +0100 Message-ID: <157117614109.15019.15677943675625422728.stgit@warthog.procyon.org.uk> In-Reply-To: <157117606853.15019.15459271147790470307.stgit@warthog.procyon.org.uk> References: <157117606853.15019.15459271147790470307.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 15 Oct 2019 21:49:04 +0000 (UTC) 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 289a887f6b5b..0255a5ca5097 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -462,6 +462,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from) spin_lock_irq(&pipe->wait.lock); head = pipe->head; + if (head - pipe->tail == buffers) { + spin_unlock_irq(&pipe->wait.lock); + continue; + } + pipe_commit_write(pipe, head + 1); /* Always wake up, even if the copy fails. Otherwise