Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1718631

[PATCH v2] fs/select: Fix memory corruption in compat_get_fd_set()

Path csiph.com!news.mixmin.net!feeds.phibee-telecom.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Helge Deller <deller@gmx.de>
Newsgroups linux.kernel
Subject [PATCH v2] fs/select: Fix memory corruption in compat_get_fd_set()
Date Wed, 23 Aug 2017 22:40:03 +0200
Message-ID <uhKBt-5gf-33@gated-at.bofh.it> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.8.3 (2017-05-23)
X-Provags-ID V03:K0:rE8XRVICLqVllpAEWe9f/7edpvfzj3+akrNcPxONUO0jrPJwmIR BPiIuimXSKqUgVmLFmv5R/xFiqbnLS7DD4uRrSkK2F1rv3Ct5ZDB7hux7RNjNS6VX6xKpig 9vcomKkMj1tib4XRpPWB47Q+/54fS5C+EBfJNB926m3BgozAf7ND27p68yFgMVKQituQje1 gRmbyslnHZvkS7q8d65FQ==
X-Ui-Out-Filterresults notjunk:1;V01:K0:ddUCsPUaWRw=:kp+DOTwfXUDSuHITbA4ooL HHSaycMsMsS3mZAK19Ru7ppKpS88I89Hd7nYHDiSCznfduxKPo/9tV3vKn8cTrGDoKo1t95m1 nm6BO/fcMa20ZfbMmf06gVsBuCMzPbla8R1UiaEZcSGMnUTzlQuOzuc3VoW46zE0gqEbMxxIL 6ARpfsYY69yxAYvcz5Asr3G77v4jctXIvO10s0HOYvAX4zN+uceazFpdqPqoiJHuOJBsz1XNu m7/ns8CFsPVURO7spdJLXC62pvWDVt8SKuMm04+TA8+Azh7WNf1iEeIJsqZBPzfBU/rXfDy71 EqsOaYap0gc9B5xQClzbFmLAIVle/WZ43X7i331RP3AFEEKmkBXGQ0+ksmF6vMaGESS+eFmjm CBIEG1uzUfQlKDu85By/iLimn5DLxrQ+8ibYsQgZomm5zrGn6n+37/fcCrCxhOx4p6yzOoWKG I4dUg3RYHb/FaNRvo8wkMeE+Ax6ONkJHuJLBcQhPQpEbKr2sbACdeFIpD2aGBe3JRrCkcezKY tKNVOEY6E3oES8E94+arVwX7noY93SFiAYALAGb2gOTgte0cGiHp4hp0jE0fr9/NghvQq8ANq 0NFQI+dAV/+zP7JqGUpfjuwofgbtzzZW0vnvXDowgXdbCJwiow5l1UlZHyr4moneujTGX27sU w3dnWLQ8txkDonOczn2khIfM6cAvCpLXoD8v4zi2biTvTYDVGPAliEAcHE/jhgFXWtcr6dPFm sE5yTDA/XqeatIH+Bw3DhJN/Rdh3Imc2+vLMrAoGLv8jMWIX5wXUIq3Yg9EUIVod2Ju7Sd1iR ySrpVFXneI2W2YDSGyPl0HRh8ERlw==
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 50
Organization linux.* mail to news gateway
X-Original-Cc John David Anglin <dave.anglin@bell.net>, linux-parisc@vger.kernel.org
X-Original-Date Wed, 23 Aug 2017 22:37:00 +0200
X-Original-Message-ID <20170823203700.GA29614@ls3530.fritz.box>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1718631

Show key headers only | View raw


Commit 464d62421cb8 ("select: switch compat_{get,put}_fd_set() to
compat_{get,put}_bitmap()") changed the calculation on how many bytes
need to be zeroed when userspace handed over a NULL pointer for a
fdset array in the select syscall.

The calculation was changed in compat_get_fd_set() wrongly from
	memset(fdset, 0, ((nr + 1) & ~1)*sizeof(compat_ulong_t));
to
	memset(fdset, 0, ALIGN(nr, BITS_PER_LONG));

The ALIGN(nr, BITS_PER_LONG) calculates the number of bits which
need to be zeroed in the target fdset array (rounded up to the next
full bits for an unsigned long).
But the memset() call expects the number of bytes to be zeroed.

This leads to clearing more memory than wanted (on the stack area or
even at kmalloc()ed memory areas) and to random kernel crashes as we
have seen them on the parisc platform.

The correct change should have been
	memset(fdset, 0, (ALIGN(nr, BITS_PER_LONG) / BITS_PER_LONG) * BYTES_PER_LONG);
which is the same as can be archieved with a call to
	zero_fd_set(nr, fdset).

Fixes: 464d62421cb8 ("select: switch compat_{get,put}_fd_set() to compat_{get,put}_bitmap()"
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Helge Deller <deller@gmx.de>
---
Changes between v1 and v2 of the patch:
- Rephrased description of the problem

diff --git a/fs/select.c b/fs/select.c
index 9d5f15e..c6362e3 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -1164,11 +1164,7 @@ int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
 	if (ufdset) {
 		return compat_get_bitmap(fdset, ufdset, nr);
 	} else {
-		/* Tricky, must clear full unsigned long in the
-		 * kernel fdset at the end, ALIGN makes sure that
-		 * actually happens.
-		 */
-		memset(fdset, 0, ALIGN(nr, BITS_PER_LONG));
+		zero_fd_set(nr, fdset);
 		return 0;
 	}
 }

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH v2] fs/select: Fix memory corruption in compat_get_fd_set() Helge Deller <deller@gmx.de> - 2017-08-23 22:40 +0200

csiph-web