Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5072807pxb; Mon, 15 Feb 2021 08:48:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwk0Qe74gcNsHrvb62rbZjt4M6j0Zm4K2qaFwN9yzIczYGPhEWzR6pfY1TLnsM8PCYZKAs X-Received: by 2002:a05:6402:1548:: with SMTP id p8mr6699347edx.287.1613407680362; Mon, 15 Feb 2021 08:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613407680; cv=none; d=google.com; s=arc-20160816; b=VNZKSho3NMBoWyErxmUuK2ToO47EX/8kB/BgGDb8W5Ih38jrvcOLywjQz+lKKko9KF 58FxOU5J5EuTYz12eSp+PDp403XlkaUFF/G7NgQGrXr1GGeLMgjjRZfDCmNk7+LAAWz2 PJNrsBxAvkGxsaS0p61cqs03Cs99/Yoee7gWUAOemhBk6wD/r+WibaRjg/Ihd09NBO/Q NHHkdNXdkiJ9NPRHHBJ6gM8LJj9g8GaeEhxoEWhmJBqFInaHRR/wllQ9ySqth7jeLMa0 hMxczOOVNbxJWkuskyv6AXg1byP4xu2Iljk2MF5L2rlsn+CpXj8b7uA71kI13F9Xkx6Q 1WWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EMxHmAfCOml9QQ7v1XLdbbMvRu5c0N8igJALrwzthLI=; b=H4HBHDwZoqkzidUuHPgxSE+nXKk9GUwh75xoXBQSgNrqVwNtuQcJ4wl+58GrbHViC2 TtsKt8hzvZWdAX00TzRtIDqEOuQy8zNs5SutClnnDHG7Qexoor43ZFIkuf/FgnYgwxn6 EMDjbusNU65/Yf0BxsIqQt+4pmuxIFX8f1+IGlIAygSiDPSLeDANr8zgo1VQO8JfRUov Eqlbgm25GGs+JpbMTggOeap69D+IZBqN8UB9JJGa1d8/gZu+Emz2jh6K/XZRO+Qv9I6k Me6s8j9nYMKGZYEhyNMk84aoCiDOU+gyFgEJpWeqYuZIw3Uwpe9dxU6gMCw5sndAJ9sh esQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R6kXfWqx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a25si1955494edt.342.2021.02.15.08.47.36; Mon, 15 Feb 2021 08:48:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R6kXfWqx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231463AbhBOQoW (ORCPT + 99 others); Mon, 15 Feb 2021 11:44:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:49600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbhBOPiH (ORCPT ); Mon, 15 Feb 2021 10:38:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FCD964EEA; Mon, 15 Feb 2021 15:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403239; bh=FydyvUabgfSj0tpi0vAQQgW4003YdZy9X1JeOpqxO58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R6kXfWqx8zgydPAa919nOAzZkKL4eF0+l3X6QGU4/RXiArPLo8BaPqWEJSzx3Nn3K 5vPRZf7bGMi9lq/eZjZrGtiNvp+27J/LeoLEJZJLlR+2l8QIsF7AMx2klKx+bSJ1N8 whlc1CESZnSm8lypSLuDzLuffJ3OMpa00UNlfhno= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Kees Cook , Nick Desaulniers , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 044/104] ubsan: implement __ubsan_handle_alignment_assumption Date: Mon, 15 Feb 2021 16:26:57 +0100 Message-Id: <20210215152720.898348168@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Chancellor [ Upstream commit 28abcc963149e06d956d95a18a85f4ba26af746f ] When building ARCH=mips 32r2el_defconfig with CONFIG_UBSAN_ALIGNMENT: ld.lld: error: undefined symbol: __ubsan_handle_alignment_assumption referenced by slab.h:557 (include/linux/slab.h:557) main.o:(do_initcalls) in archive init/built-in.a referenced by slab.h:448 (include/linux/slab.h:448) do_mounts_rd.o:(rd_load_image) in archive init/built-in.a referenced by slab.h:448 (include/linux/slab.h:448) do_mounts_rd.o:(identify_ramdisk_image) in archive init/built-in.a referenced 1579 more times Implement this for the kernel based on LLVM's handleAlignmentAssumptionImpl because the kernel is not linked against the compiler runtime. Link: https://github.com/ClangBuiltLinux/linux/issues/1245 Link: https://github.com/llvm/llvm-project/blob/llvmorg-11.0.1/compiler-rt/lib/ubsan/ubsan_handlers.cpp#L151-L190 Link: https://lkml.kernel.org/r/20210127224451.2587372-1-nathan@kernel.org Signed-off-by: Nathan Chancellor Acked-by: Kees Cook Reviewed-by: Nick Desaulniers Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- lib/ubsan.c | 31 +++++++++++++++++++++++++++++++ lib/ubsan.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/lib/ubsan.c b/lib/ubsan.c index cb9af3f6b77e3..adf8dcf3c84e6 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -427,3 +427,34 @@ void __ubsan_handle_load_invalid_value(void *_data, void *val) ubsan_epilogue(); } EXPORT_SYMBOL(__ubsan_handle_load_invalid_value); + +void __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr, + unsigned long align, + unsigned long offset); +void __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr, + unsigned long align, + unsigned long offset) +{ + struct alignment_assumption_data *data = _data; + unsigned long real_ptr; + + if (suppress_report(&data->location)) + return; + + ubsan_prologue(&data->location, "alignment-assumption"); + + if (offset) + pr_err("assumption of %lu byte alignment (with offset of %lu byte) for pointer of type %s failed", + align, offset, data->type->type_name); + else + pr_err("assumption of %lu byte alignment for pointer of type %s failed", + align, data->type->type_name); + + real_ptr = ptr - offset; + pr_err("%saddress is %lu aligned, misalignment offset is %lu bytes", + offset ? "offset " : "", BIT(real_ptr ? __ffs(real_ptr) : 0), + real_ptr & (align - 1)); + + ubsan_epilogue(); +} +EXPORT_SYMBOL(__ubsan_handle_alignment_assumption); diff --git a/lib/ubsan.h b/lib/ubsan.h index 7b56c09473a98..9a0b71c5ff9fb 100644 --- a/lib/ubsan.h +++ b/lib/ubsan.h @@ -78,6 +78,12 @@ struct invalid_value_data { struct type_descriptor *type; }; +struct alignment_assumption_data { + struct source_location location; + struct source_location assumption_location; + struct type_descriptor *type; +}; + #if defined(CONFIG_ARCH_SUPPORTS_INT128) typedef __int128 s_max; typedef unsigned __int128 u_max; -- 2.27.0