From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 656D4C00454 for ; Tue, 10 Dec 2019 21:29:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 35D89205C9 for ; Tue, 10 Dec 2019 21:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576013345; bh=zOKZqSf4jAxFn+TyXskDfTFMnxYCixEt7x57fI3Jy/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KN/QZPondPQ0zF8UDJTkZt6d4Jaj9y9kin66V+r9MA2vb1s80YLApW5G16/HhwP2X QaHODIt/zmr9VNGk21ggrGTNQgsFUKpx7JlfsF0j3J/jGrjlj3bQutKuHBqn80+lkh fzejci9NAoofpp6onQLtSe//cYjkkDYNI4vPf2vM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728665AbfLJV3E (ORCPT ); Tue, 10 Dec 2019 16:29:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:59948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728434AbfLJVKR (ORCPT ); Tue, 10 Dec 2019 16:10:17 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 829F8246A3; Tue, 10 Dec 2019 21:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576012216; bh=zOKZqSf4jAxFn+TyXskDfTFMnxYCixEt7x57fI3Jy/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ouuWJ2pzec7JHrkH0ep6Wy8PtDIpQoZur3iNfGtoJSls7SOoP4vXpVDirJbkY7QjM TcIskpnz3PhUw7RxyZ3936pt6lbDjW71sZUdRCMHZ7QvMmcxnlKBilY7WWIdxr5+Lq Ot5+HdXyBdn/ikPMjErl16WKJwQvLLFtu/neQrao= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Zijlstra , Randy Dunlap , 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 AUTOSEL 5.4 167/350] ubsan, x86: Annotate and allow __ubsan_handle_shift_out_of_bounds() in uaccess regions Date: Tue, 10 Dec 2019 16:04:32 -0500 Message-Id: <20191210210735.9077-128-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191210210735.9077-1-sashal@kernel.org> References: <20191210210735.9077-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 e7d31735950de..0c4681118fcd2 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 543c068096b12..4768d91c6d686 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -482,6 +482,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