Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3002526ybi; Mon, 17 Jun 2019 14:26:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyo8+tCtp+wFzHX3p7zGT4nZIdO/xS1hw9XeP1DNMtmHc2yny6xmztwK2xLl2/Pr9nQNGkt X-Received: by 2002:a62:4e0c:: with SMTP id c12mr113684404pfb.17.1560806808143; Mon, 17 Jun 2019 14:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806808; cv=none; d=google.com; s=arc-20160816; b=HUDu0YKVZEj1YBc1qg8oxc2ut18ZSwjd6D2ls8IBoqhJFf8TOD19Lt7q8ttTQtofeg olARKvRCEF2KwFtMVzF9EWvd36ZzPP82ntAOjhykRNQXI/P4p1Carbs5faNx1OPwJAzj ILIGD+3APU3HL2JDhGdJOy/MYOvx0QFMqQWx1rWNsWbQ6GXZYMPjT8PXQCdRcrFL48OR 0ZtDnWfyHuULE5b0mBiSX1YpX+VMfX2x+1JcSsZENfEtQOBJ5nfobgnEqpbKYA4joEiZ QZ5Kd41aFJpOl3i0HRa48I/3GxbJ6wPLmTmbdNwavN2QQRq0eDfKoch0w2R8FtzBEga0 RFpA== 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:subject:cc:to :from:dkim-signature; bh=16yABNd1fYpdthB806uqo6bDbaXjLbvgU5b4CjETJd8=; b=h2rvxRPgxr88xBEsWBOR3SVsJK8u+kTddE0ydTKZN7Rjov8VOmjXO3EN8HE6RMTa+Y M8XTro2G9d4CIwdn3w+2wUA4O1keZQ46xn48gIgXgu+MvWOQGqNRy9aIQi7O0gpA1bWs 3l9KHN6Z0ozVF8wKyXcwoUrrMmk+Tz6iZBkiJ4Po7ju/9KrinkwoZaQSbuoDSPrUZfeg TcsL+PN3wND7k2hZwvIMQ2nH6uhLpq8KLqdyLihjVAC+WITv5ZjcxkN5NL1DJk/GAQ5x URZO5m1Yr2TTocRkVGScucn2eZ0ODuIH6dcKiVZF5pMKWk5hjD2uRHZYWp3bFhomiGjV QdWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NkzD7DpZ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si11858223pgq.173.2019.06.17.14.26.32; Mon, 17 Jun 2019 14:26:48 -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=@kernel.org header.s=default header.b=NkzD7DpZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729944AbfFQVYb (ORCPT + 99 others); Mon, 17 Jun 2019 17:24:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:50144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728963AbfFQVYa (ORCPT ); Mon, 17 Jun 2019 17:24:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E54D52063F; Mon, 17 Jun 2019 21:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806669; bh=welHjufBx5KtGae43pwEQmzihyKLa93/yiYwieSvCQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NkzD7DpZVHnms1cy8zUkPGlQOYUFRjNzeW5UZ/ffDMqAy5WRD8TfxPmtg+070iBUo 7vhBVPZ6xCCASYUHApFz7UWFe3BLZZ4WnBqAICS9lkb+awTAQKP1TjwtA3eVVUtn7K QdSlYPC+5v975Dc7canxuQm1plGVbFMzlQhNcdYc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrei Vagin , syzbot+0d602a1b0d8c95bdf299@syzkaller.appspotmail.com, "Eric W. Biederman" , Sasha Levin Subject: [PATCH 4.19 17/75] [PATCH] signal/ptrace: Dont leak unitialized kernel memory with PTRACE_PEEK_SIGINFO Date: Mon, 17 Jun 2019 23:09:28 +0200 Message-Id: <20190617210753.532172735@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210752.799453599@linuxfoundation.org> References: <20190617210752.799453599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit f6e2aa91a46d2bc79fce9b93a988dbe7655c90c0 ] Recently syzbot in conjunction with KMSAN reported that ptrace_peek_siginfo can copy an uninitialized siginfo to userspace. Inspecting ptrace_peek_siginfo confirms this. The problem is that off when initialized from args.off can be initialized to a negaive value. At which point the "if (off >= 0)" test to see if off became negative fails because off started off negative. Prevent the core problem by adding a variable found that is only true if a siginfo is found and copied to a temporary in preparation for being copied to userspace. Prevent args.off from being truncated when being assigned to off by testing that off is <= the maximum possible value of off. Convert off to an unsigned long so that we should not have to truncate args.off, we have well defined overflow behavior so if we add another check we won't risk fighting undefined compiler behavior, and so that we have a type whose maximum value is easy to test for. Cc: Andrei Vagin Cc: stable@vger.kernel.org Reported-by: syzbot+0d602a1b0d8c95bdf299@syzkaller.appspotmail.com Fixes: 84c751bd4aeb ("ptrace: add ability to retrieve signals without removing from a queue (v4)") Signed-off-by: "Eric W. Biederman" Signed-off-by: Sasha Levin --- kernel/ptrace.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index fc0d667f5792..ed33066a9736 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -704,6 +704,10 @@ static int ptrace_peek_siginfo(struct task_struct *child, if (arg.nr < 0) return -EINVAL; + /* Ensure arg.off fits in an unsigned long */ + if (arg.off > ULONG_MAX) + return 0; + if (arg.flags & PTRACE_PEEKSIGINFO_SHARED) pending = &child->signal->shared_pending; else @@ -711,18 +715,20 @@ static int ptrace_peek_siginfo(struct task_struct *child, for (i = 0; i < arg.nr; ) { siginfo_t info; - s32 off = arg.off + i; + unsigned long off = arg.off + i; + bool found = false; spin_lock_irq(&child->sighand->siglock); list_for_each_entry(q, &pending->list, list) { if (!off--) { + found = true; copy_siginfo(&info, &q->info); break; } } spin_unlock_irq(&child->sighand->siglock); - if (off >= 0) /* beyond the end of the list */ + if (!found) /* beyond the end of the list */ break; #ifdef CONFIG_COMPAT -- 2.20.1