Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13474907ybl; Sun, 29 Dec 2019 12:47:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwQjpzFRFjmF0+gZVM+RpLEfzJ7cM0bN3VfCsa+VI/CwgQsQ0oJeBmZ9Kg36eQCn1zy9TrJ X-Received: by 2002:a05:6830:1185:: with SMTP id u5mr65909907otq.147.1577652474530; Sun, 29 Dec 2019 12:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652474; cv=none; d=google.com; s=arc-20160816; b=lxb21d3lhhAGxNV0WD7Gw/oiIQmq24TrVX9EMscjrjsytIMrSY8x+uQSBOWR19tBMV i3dNtempG9+BGA/U8tJpiR7SQigVooQvba1EzDBQMgU9SmjY0f02NubvsGdjiUPita2i z5dAMOvyvYL0JW150+RHA48EifVD6gXIHvA3/u/zvPKdiwf5Ckj94bwJu3IEF7WleNjC Nyz7uJsFxaV1eWywLnX3H6ZcqRs652lslT+kV3TNqkK3Cd2felAxU6UsCcjqRptd8OwD PwhvlSVgeMQGY2ZXUM0JXGFT8CzwIJHH9DNysFMrBSUqUpo91EzCGqqZuej6rVx8pbsW rRtA== 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=6Hu4BKW9g2sT0iq2w73ljukn4F4v6iwCjzVzgUEcm0c=; b=HIMPzzpu3O+I97CboRskIaZY10EZA8SfyMNd9Pwf0ajQI9P1JURrk+7YkA7XY4sMZ4 rbOWB35GX89O1elrR/N9ZOybFdtLl14301Iwi12lsCrTxCxmluDaeHDrDGhRskNpuN+a r/K88TZh82Xjv5W3MCQuUI1Teh5V2q4tthOJrpBAw1gWJ66hX+xA3mVkNhpNjbJK76RX 3oGLwLvIXn47C1pYFkgfreKNWlsLxeazxhNgPoBNhkqI6sow8JevZhplVUlYpbKHfWQ+ cXU+Y6T7xAfbAZ4tg7r/7s1IJCzwMRbCuHdLUeHY36OjA6wjBnYhHZ+V6FneI5VcCO/0 FqEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I5Hpuk+P; 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 q28si18889253oij.149.2019.12.29.12.47.43; Sun, 29 Dec 2019 12:47:54 -0800 (PST) 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=I5Hpuk+P; 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 S1731988AbfL2Ru4 (ORCPT + 99 others); Sun, 29 Dec 2019 12:50:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:35686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731972AbfL2Ru4 (ORCPT ); Sun, 29 Dec 2019 12:50:56 -0500 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 6B88320718; Sun, 29 Dec 2019 17:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641854; bh=eyMennrsYxgBk8lQdqcO0vm1enPfe43n+1GlBfz2JkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5Hpuk+PoMNhbKTgx+W9ob4TFVa3yn7ILKfw0rZ0XSXDw1CFCQRUhoYD5hLnEmwpd SoehZxbbnalmd7FpkEo96vPWUllGGyK1FW1CGcDx8ntIeNH6mSxArA5YLmrPMgyK37 6b0cZxyk9PQ/aXFbTyczW7WEcz0jAP7tMJBnlTT0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Randy Dunlap , "Peter Zijlstra (Intel)" , Christian Brauner , Josh Poimboeuf , Linus Torvalds , Stephen Rothwell , Thomas Gleixner , cyphar@cyphar.com, keescook@chromium.org, linux@rasmusvillemoes.dk, Ingo Molnar , Sasha Levin Subject: [PATCH 5.4 196/434] ubsan, x86: Annotate and allow __ubsan_handle_shift_out_of_bounds() in uaccess regions Date: Sun, 29 Dec 2019 18:24:09 +0100 Message-Id: <20191229172714.846581295@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@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 From: Peter Zijlstra [ Upstream commit 9a50dcaf0416a43e1fe411dc61a99c8333c90119 ] The new check_zeroed_user() function uses variable shifts inside of a user_access_begin()/user_access_end() section and that results in GCC emitting __ubsan_handle_shift_out_of_bounds() calls, even though through value range analysis it would be able to see that the UB in question is impossible. Annotate and whitelist this UBSAN function; continued use of user_access_begin()/user_access_end() will undoubtedly result in further uses of function. Reported-by: Randy Dunlap Tested-by: Randy Dunlap Signed-off-by: Peter Zijlstra (Intel) Acked-by: Randy Dunlap Acked-by: Christian Brauner Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephen Rothwell Cc: Thomas Gleixner Cc: cyphar@cyphar.com Cc: keescook@chromium.org Cc: linux@rasmusvillemoes.dk Fixes: f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper") Link: https://lkml.kernel.org/r/20191021131149.GA19358@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- lib/ubsan.c | 5 ++++- tools/objtool/check.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ubsan.c b/lib/ubsan.c index e7d31735950d..0c4681118fcd 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -374,9 +374,10 @@ void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data, struct type_descriptor *lhs_type = data->lhs_type; char rhs_str[VALUE_LENGTH]; char lhs_str[VALUE_LENGTH]; + unsigned long ua_flags = user_access_save(); if (suppress_report(&data->location)) - return; + goto out; ubsan_prologue(&data->location, &flags); @@ -402,6 +403,8 @@ void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data, lhs_type->type_name); ubsan_epilogue(&flags); +out: + user_access_restore(ua_flags); } EXPORT_SYMBOL(__ubsan_handle_shift_out_of_bounds); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 044c9a3cb247..f53d3c515cdc 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -481,6 +481,7 @@ static const char *uaccess_safe_builtin[] = { "ubsan_type_mismatch_common", "__ubsan_handle_type_mismatch", "__ubsan_handle_type_mismatch_v1", + "__ubsan_handle_shift_out_of_bounds", /* misc */ "csum_partial_copy_generic", "__memcpy_mcsafe", -- 2.20.1