Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144472pxv; Fri, 9 Jul 2021 19:25:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZBqkX0TXASxAYb+4szt/TagCdXQnkB2BiM1V7W5pRGmAcw27t3rscRmxKVW2E9ogGAmO6 X-Received: by 2002:a05:6402:51c9:: with SMTP id r9mr49694291edd.326.1625883910013; Fri, 09 Jul 2021 19:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883910; cv=none; d=google.com; s=arc-20160816; b=uzXt/Lu9NKeiryjfb+768iq4I87GnuCmGsTnebzW6uZBdCl87Hrw3WaY1KC5+315o3 z9AHl39Xq/aEyyWa9BJTVjWVbP6lM0kOj9o5kKj10zq0gfHfEtsEQzTurMkRbgaHRB0D JnlXBBhV1aPd4ni3B7W1hHN/qNAabKkegjQZ0DzmPd85j9t/5bgwA0OkznjAozFd1Dol AyvY+amVOAlxFP5+Hi2giTNDMfngf10K0/Tk8OvFt1wQo6Yr20KESy1ScCkZudy6DqvD /3jt40FnEDcpk0oMEAc8M/4/pI0Smp01FP0G47ljDthJrClD5ButszC6pqszY0aLuAh1 Mnaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S9HmiIdBwwXlWHcjXk3zD1vOcU7WRy8DcojBKI9h+d0=; b=PU+gSOt+bwnPkP5C4dtd28JYwrN7YH8dXJp3/5k8bBuzfmoGZ1rBrMUmx/Kr7QTSH1 6BucIyf9nOq0bF9wWv4LNBKqCha2qr37TvClbrv/avy3log+BgvPBJmW4AriyDur2X5D 6gAqwpQCYTPFEWCwBZd6JcmpjfKzie+FOpRoeFWNCfvouCLZaaw8FMdsqoh2rBmmppg/ c6vC69zMZ1H+18myuYhj8NLCJtDLxSwtDhtdzyJjFzVyjrzWJP9b8FI4T9njQivrQwmn Zm58wDQ1hZQRucJ1mdTRsC9RI7lHFIH+gsCKTjKkR3G5MQjufwKg8U99k9KVhmHQJeAH ZcTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PWzZ9pst; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id em10si8928723ejc.186.2021.07.09.19.24.47; Fri, 09 Jul 2021 19:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PWzZ9pst; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232609AbhGJCWt (ORCPT + 99 others); Fri, 9 Jul 2021 22:22:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:38804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232437AbhGJCVt (ORCPT ); Fri, 9 Jul 2021 22:21:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80DC361419; Sat, 10 Jul 2021 02:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883544; bh=HAf0RaDTzDP5F1hXJJDZbhvANHYbr8yOdM2uGhwNgiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PWzZ9pstKDLQjTYsSSze3jwcJ9ZCjEA3cg5DX6CXBiciUIn9NZVnsGBcMA9MvJ5NX 0U/XBYFA+UlKfCkT0pBEHVA9XSh54BDTez6fmacEjy4ldMamP47XraSwmuyoPEXVbd ojVX5hLcLEzGrQCtVGjsw8Vxb65LSOnE9+K7NXhnCUSDObMmh4whTqyvNpFA5tLt3K TJRSBxgBlwyJBIXFeZkVy5v/HeMBIMoSFRw+qRO8VPEAEyth3OgACx5gqaX1nTmmh4 wXmApafNDucJ3FztGSrAkdPQUcJgnLya7Hl7+z+klV4tLIM0xK8vjPx4mrmLMs7Dwe xZGLRZwOl86JA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , Sasha Levin Subject: [PATCH AUTOSEL 5.13 055/114] iov_iter_advance(): use consistent semantics for move past the end Date: Fri, 9 Jul 2021 22:16:49 -0400 Message-Id: <20210710021748.3167666-55-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro [ Upstream commit 3b3fc051cd2cba42bf736fa62780857d251a1236 ] asking to advance by more than we have left in the iov_iter should move to the very end; it should *not* leave negative i->count and it should not spew into syslog, etc. - it's a legitimate operation. Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- lib/iov_iter.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index c701b7a187f2..82a889283eca 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1092,8 +1092,6 @@ static inline void pipe_truncate(struct iov_iter *i) static void pipe_advance(struct iov_iter *i, size_t size) { struct pipe_inode_info *pipe = i->pipe; - if (unlikely(i->count < size)) - size = i->count; if (size) { struct pipe_buffer *buf; unsigned int p_mask = pipe->ring_size - 1; @@ -1134,6 +1132,8 @@ static void iov_iter_bvec_advance(struct iov_iter *i, size_t size) void iov_iter_advance(struct iov_iter *i, size_t size) { + if (unlikely(i->count < size)) + size = i->count; if (unlikely(iov_iter_is_pipe(i))) { pipe_advance(i, size); return; @@ -1143,7 +1143,6 @@ void iov_iter_advance(struct iov_iter *i, size_t size) return; } if (unlikely(iov_iter_is_xarray(i))) { - size = min(size, i->count); i->iov_offset += size; i->count -= size; return; -- 2.30.2