Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp257661ybi; Wed, 29 May 2019 20:48:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwljXl7bQoBDOexziFRPTtTyJ7AkIU8Lxn0OcvGhi4OWO7NOBAb3g3QG09goEUVoT0oMlfT X-Received: by 2002:aa7:8598:: with SMTP id w24mr1549252pfn.160.1559188120015; Wed, 29 May 2019 20:48:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188120; cv=none; d=google.com; s=arc-20160816; b=zjKtBXBSUiqrljV9yyRjk0s0OIE8oyrOirwHXp2tsyUARqjlf+DKOLzDK4L0PQ+vsD jal8XfuxBMlal6BYJSXJXcZSpY/b+JP5m8l/+NuzPRE+R1NoQr4hpTCprS7M8ATq4pfC AAqrRYxi83SzmNgE0nUgxScBQcfvKS4kbaAqvvy4c0vsnJIOuq9n+z8FI7//WqtB7bfe 2vmNoHcynW6Y0lD96BKGdSJibTKejaf6O60jx1qMfnqx6SxqL3ygRNtZ/fRXjRNrSWci v2/kQGLwa2FZOD2eqNj48BN+g8zdm7+MqCqHoQwBi1CkCX6eEicd8DOMyb0H3DqADmXg yoYQ== 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=tLYm4QRA5OvriuOnxXhkOmlRWMJp867UCoQWm7ppKEU=; b=WFy8N6YMVyXZsklf9fCZfv81lN1p94L64SPMB1B3Ec9r5BGBqaWDGw6dPXtKaVsbKJ qfO+wKmEgk2jMb9hhJcMI7o0M6aQIDEmkvXl8Xm45Se9GbMjx19PI6zRDk4NaEJHtv2Z JP2tZa4xfEoXed0/4+1Fb9GhtlesbqXk79CoCAWeNUo6Ctf9kT6S2sxvJjB4daPAkm2z CbNUJsYj2UmfQoCcsN3MSQ6/sw2UiPhbs8YWJRy0RG1pW62qMF1LH7sWwAlfFkzWb8xt Cm9fBP8qrZYilLtFPP22u8XlXznmf351iu+2UvgJGbcNJbHChFPAa56ytLKMu5nG35Sf HPWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=POtrs3nm; 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 l7si1787034plg.222.2019.05.29.20.48.24; Wed, 29 May 2019 20:48:40 -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=POtrs3nm; 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 S1732626AbfE3Dpm (ORCPT + 99 others); Wed, 29 May 2019 23:45:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:59924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732322AbfE3DUr (ORCPT ); Wed, 29 May 2019 23:20:47 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 DA5032496D; Thu, 30 May 2019 03:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186445; bh=qydilEWEQqasVCq9cYkBAWbqdN+AQcFoT0hQC5NMJ3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=POtrs3nm9ynx4f5GEUc6Y1cy1y6a1pUcxixIXTWKNzLklLRfXJQEj7b9xu5YQXubM 2rj+i3Q4LGeShFyXSeDBw8WkP46H880jR5JpEb2lxGwnoXINebYEKqG460tnAeAGnL +Kqt40YWBTuOaqR4O7Y+50HmXepbltKnH0cr55dI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Randy Dunlap , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , luto@kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.9 053/128] mm/uaccess: Use unsigned long to placate UBSAN warnings on older GCC versions Date: Wed, 29 May 2019 20:06:25 -0700 Message-Id: <20190530030444.261281524@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030432.977908967@linuxfoundation.org> References: <20190530030432.977908967@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 29da93fea3ea39ab9b12270cc6be1b70ef201c9e ] Randy reported objtool triggered on his (GCC-7.4) build: lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x315: call to __ubsan_handle_add_overflow() with UACCESS enabled lib/strnlen_user.o: warning: objtool: strnlen_user()+0x337: call to __ubsan_handle_sub_overflow() with UACCESS enabled This is due to UBSAN generating signed-overflow-UB warnings where it should not. Prior to GCC-8 UBSAN ignored -fwrapv (which the kernel uses through -fno-strict-overflow). Make the functions use 'unsigned long' throughout. Reported-by: Randy Dunlap Signed-off-by: Peter Zijlstra (Intel) Acked-by: Randy Dunlap # build-tested Acked-by: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: luto@kernel.org Link: http://lkml.kernel.org/r/20190424072208.754094071@infradead.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- lib/strncpy_from_user.c | 5 +++-- lib/strnlen_user.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 7e35fc450c5bb..5a07f19059c36 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -22,10 +22,11 @@ * hit it), 'max' is the address space maximum (and we return * -EFAULT if we hit it). */ -static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max) +static inline long do_strncpy_from_user(char *dst, const char __user *src, + unsigned long count, unsigned long max) { const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; - long res = 0; + unsigned long res = 0; /* * Truncate 'max' to the user-specified limit, so that diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 8e105ed4df12b..9ff4f3bbb1aae 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -27,7 +27,7 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max) { const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; - long align, res = 0; + unsigned long align, res = 0; unsigned long c; /* @@ -41,7 +41,7 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count, * Do everything aligned. But that means that we * need to also expand the maximum.. */ - align = (sizeof(long) - 1) & (unsigned long)src; + align = (sizeof(unsigned long) - 1) & (unsigned long)src; src -= align; max += align; -- 2.20.1