Message ID | 20230302224946.never.243-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp112403wrd; Thu, 2 Mar 2023 15:02:42 -0800 (PST) X-Google-Smtp-Source: AK7set+LRbqEMdcwlh2SQWisU6igfig8dv+y09gbUSKJKC3a91I4OfsXib7vDkOtkPmehYwcz8GG X-Received: by 2002:a17:907:3f9e:b0:8aa:33c4:87d5 with SMTP id hr30-20020a1709073f9e00b008aa33c487d5mr15289054ejc.10.1677798162793; Thu, 02 Mar 2023 15:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677798162; cv=none; d=google.com; s=arc-20160816; b=oFkcHsgrb+XHDbigB7oMjmqUzMVikezUqMbma8uoaaUPyR9iL+cDcpE65KS9va3lrS xNefE8bqdbhQMVEGqbbtCZ5nSEOcHFKyR+rloFAlGyD/aR+tWLJdINmBnI+O2s2o0E3/ JwS1iZmbskzcVPQn6XCfYIKRS8zH32O/m2QUz/MwN2Qh3diL7TVsmpvUlnwpIO0xwgpy sxkngZ0zHLdVPhXwdV/ZQQyFe2ss+nAd18VTiSvIPdSwBiKuCsTX5A3BjZ7QqG5WpCqz RityErsWY5D3qr/cz6avY2V1eyjlefa+lDePgiKgAH0Pih+GzgE86jQ3fnFlx4Z6JDnZ 7uww== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=87r3ryuddMp2n2OJgEocLi5hCbxjRwWfqUz8IuAFVl0=; b=lXbUAC7IHotkOZ3MwJWfgB2Of79jj47XKbJ4NODy7+YZQXPHxC47UnheJxEfxdr8Mv rHXOio9AIjil8a+6tgXH4h8a8qApeg4mUQ9MunAXm9KVuyBdqvgQWTJLLk12hGh4EGvk v1h1U0/1g/7e4TVRfWn62canORnCuCrhYefxqCY5aMKsKzgGlyFwRqDR++d+mQNtcnjG yXs8SaqzXAI38EpkNLKxRU2I/I3dht29CUAHRUdhxr5VcmieZ7ZiSJAvtXA0mYURxcHH fx/BAyYYQs5fni90cKb5GPsU2S+8IVs2G9dGZ8gkhIRhOfA6Dwb0rzoxJzxw4xIpF6Eh XAFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KJYLa2os; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020aa7c656000000b004c0da1cf02dsi879290edr.105.2023.03.02.15.02.10; Thu, 02 Mar 2023 15:02:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KJYLa2os; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbjCBWt5 (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Thu, 2 Mar 2023 17:49:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjCBWtz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Mar 2023 17:49:55 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C77F23650 for <linux-kernel@vger.kernel.org>; Thu, 2 Mar 2023 14:49:53 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id z2so823373plf.12 for <linux-kernel@vger.kernel.org>; Thu, 02 Mar 2023 14:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1677797393; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=87r3ryuddMp2n2OJgEocLi5hCbxjRwWfqUz8IuAFVl0=; b=KJYLa2os+yE0S+tQquXclEo5UjbB3+Ix9L7t+KQV3eWYy49UoX7lkm4pdsI0DCG2xP 1Zb5VEgb0JZwWKs5XjvOkNJmi2QFtZJxCjvVNdN4NIi6tT4yT1bRDmW6x7vkkY/W0SBp grxfEqQ+YXXSh+Uj6LgzHidfiHyt2I/MWu8XU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677797393; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=87r3ryuddMp2n2OJgEocLi5hCbxjRwWfqUz8IuAFVl0=; b=mEdO/xBlxVFCGnBGCBZcv/iwNqrUKpRg+3Vyv97mDLPnFO3aY/OS9GFvfqRi0JemX9 wItl8w2xdUKPNKU5W7cEVyclH4+PJ3XwPSxPcUYuB4lzPfUDPLP7uZIRs9N8SPtxw7Q/ hFQeqdytnyVtDfwZZw9uDRtt4iC6n2u6p2+oeUk59SVPdKXChdMJoim3zgA15Cq08Reu Q+++9Ywr/hzf4bLZTOT63RYhfpnaSpBbGdlK9JgwdzefPaU6/PYSqsSGxdqYqOFk3FgZ gEHUbqmzuSsBzC8SzlUKd5jlzyvsnBJK7F9hiaKqEOnjvu+/+SXczlh9EdDKZlYwU/Kh 0JpQ== X-Gm-Message-State: AO0yUKUSkd+Biq93L+fAZmXLoLSeJE0n4LFnmaMayeZ4TOBVf6jUe5E3 h6CJkrqPjwDlra+E69z1gFU4Lg== X-Received: by 2002:a05:6a20:160c:b0:cd:1cce:d892 with SMTP id l12-20020a056a20160c00b000cd1cced892mr139958pzj.9.1677797393110; Thu, 02 Mar 2023 14:49:53 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id e19-20020a62aa13000000b005b6f63c6cf4sm217194pff.30.2023.03.02.14.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 14:49:52 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: Joel Fernandes <joel@joelfernandes.org> Cc: Kees Cook <keescook@chromium.org>, Jakub Kicinski <kuba@kernel.org>, stable@vger.kernel.org, Masahiro Yamada <yamada.masahiro@socionext.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] kheaders: Use array declaration instead of char Date: Thu, 2 Mar 2023 14:49:50 -0800 Message-Id: <20230302224946.never.243-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2075; h=from:subject:message-id; bh=eLj/PflKjatP3hFY0i0HHeuMwWpjFzg2cBxv81U9QkM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBkASgOFlZ1ftATS5I9PtciOtLxZpppkpTfsbekhvi0 AiYPKIuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZAEoDgAKCRCJcvTf3G3AJkeqD/ 0UKRxmCYQN06lvmilRYvIyKjBpP1mKZf3n4bjCclIFAOJ/ZLkeIiUPLMpOo34kP1jZOaaJapJsc3th WwaEdtGNaVCu8UyDipj4c1YBMdSYL1xekEJtkPnelZnDwEutxQNxEy38mpAgoCb541wlTw9w0YbPAi yyJa+NJI5l/x2IxhPwKD3F19cxe9JlWTBqC82IpvTUY7l9jxv1XcnM4ZJA0D5mlyDzOovN10GhQdVj aEPKTTjm8ifvUsuiODnrsguQPwwvoadopjqjwgGLlmxM9G6IfAD8F1zIWFo6XFsPfrxhRaQvO/bjcm GLXRBa3GPb0I05K21/lSkajRvk5xOfs+FSpF9S+PztoqgHOnI4wDRrL6zhdp7JzxZQ6IzVsukq1Xqe UUuvWc4OfJN2Q8j3Jkb4aq3NPpQPMnvOip9hlQdEpgRR4foO95+kX2XpQ3nK1uODIiDxCb3y+ScURs iI+/TAUPcYLIV6i59xNWz9yNv2kfisiAXVg5AQdf9jcJbJn6LhGEaW0GlpQc6ocYRRliSxzE91OD9l UKkvUONcTKTMx7q7/bUY+E+2qmFHnoN1HUb//TPtpO1Km4DypVSVz7flMS9OWbF8y6sX/eP2Bk1ceM c8dEuWg6AeUgSV0SwOuqvYletGKA8FxVGpvNRif+xcgiCXHeBQE6QmbVeyjw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759298886274934297?= X-GMAIL-MSGID: =?utf-8?q?1759298886274934297?= |
Series |
kheaders: Use array declaration instead of char
|
|
Commit Message
Kees Cook
March 2, 2023, 10:49 p.m. UTC
Under CONFIG_FORTIFY_SOURCE, memcpy() will check the size of destination and source buffers. Defining kernel_headers_data as "char" would trip this check. Since these addresses are treated as byte arrays, define them as arrays (as done everywhere else). This was seen with: $ cat /sys/kernel/kheaders.tar.xz >> /dev/null detected buffer overflow in memcpy kernel BUG at lib/string_helpers.c:1027! ... RIP: 0010:fortify_panic+0xf/0x20 [...] Call Trace: <TASK> ikheaders_read+0x45/0x50 [kheaders] kernfs_fop_read_iter+0x1a4/0x2f0 ... Reported-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/bpf/20230302112130.6e402a98@kernel.org/ Tested-by: Jakub Kicinski <kuba@kernel.org> Fixes: 43d8ce9d65a5 ("Provide in-kernel headers to make extending kernel easier") Cc: Joel Fernandes (Google) <joel@joelfernandes.org> Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> --- kernel/kheaders.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Comments
On Thu, Mar 02, 2023 at 02:49:50PM -0800, Kees Cook wrote: > Under CONFIG_FORTIFY_SOURCE, memcpy() will check the size of destination > and source buffers. Defining kernel_headers_data as "char" would trip > this check. Since these addresses are treated as byte arrays, define > them as arrays (as done everywhere else). > > This was seen with: > > $ cat /sys/kernel/kheaders.tar.xz >> /dev/null > > detected buffer overflow in memcpy > kernel BUG at lib/string_helpers.c:1027! > ... > RIP: 0010:fortify_panic+0xf/0x20 > [...] > Call Trace: > <TASK> > ikheaders_read+0x45/0x50 [kheaders] > kernfs_fop_read_iter+0x1a4/0x2f0 > ... > > Reported-by: Jakub Kicinski <kuba@kernel.org> > Link: https://lore.kernel.org/bpf/20230302112130.6e402a98@kernel.org/ > Tested-by: Jakub Kicinski <kuba@kernel.org> Acked-by: Joel Fernandes (Google) <joel@joelfernandes.org> thanks, - Joel > Fixes: 43d8ce9d65a5 ("Provide in-kernel headers to make extending kernel easier") > Cc: Joel Fernandes (Google) <joel@joelfernandes.org> > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > kernel/kheaders.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/kernel/kheaders.c b/kernel/kheaders.c > index 8f69772af77b..42163c9e94e5 100644 > --- a/kernel/kheaders.c > +++ b/kernel/kheaders.c > @@ -26,15 +26,15 @@ asm ( > " .popsection \n" > ); > > -extern char kernel_headers_data; > -extern char kernel_headers_data_end; > +extern char kernel_headers_data[]; > +extern char kernel_headers_data_end[]; > > static ssize_t > ikheaders_read(struct file *file, struct kobject *kobj, > struct bin_attribute *bin_attr, > char *buf, loff_t off, size_t len) > { > - memcpy(buf, &kernel_headers_data + off, len); > + memcpy(buf, &kernel_headers_data[off], len); > return len; > } > > @@ -48,8 +48,8 @@ static struct bin_attribute kheaders_attr __ro_after_init = { > > static int __init ikheaders_init(void) > { > - kheaders_attr.size = (&kernel_headers_data_end - > - &kernel_headers_data); > + kheaders_attr.size = (kernel_headers_data_end - > + kernel_headers_data); > return sysfs_create_bin_file(kernel_kobj, &kheaders_attr); > } > > -- > 2.34.1 >
From: Kees Cook <keescook@chromium.org> Date: Thu, 2 Mar 2023 14:49:50 -0800 > Under CONFIG_FORTIFY_SOURCE, memcpy() will check the size of destination > and source buffers. Defining kernel_headers_data as "char" would trip > this check. Since these addresses are treated as byte arrays, define > them as arrays (as done everywhere else). Yet another array-as-one-char, I wonder how many are still here... > > This was seen with: > > $ cat /sys/kernel/kheaders.tar.xz >> /dev/null > > detected buffer overflow in memcpy > kernel BUG at lib/string_helpers.c:1027! > ... > RIP: 0010:fortify_panic+0xf/0x20 > [...] > Call Trace: > <TASK> > ikheaders_read+0x45/0x50 [kheaders] > kernfs_fop_read_iter+0x1a4/0x2f0 > ... > > Reported-by: Jakub Kicinski <kuba@kernel.org> > Link: https://lore.kernel.org/bpf/20230302112130.6e402a98@kernel.org/ > Tested-by: Jakub Kicinski <kuba@kernel.org> > Fixes: 43d8ce9d65a5 ("Provide in-kernel headers to make extending kernel easier") > Cc: Joel Fernandes (Google) <joel@joelfernandes.org> > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com> > --- > kernel/kheaders.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) [...] Thanks, Olek
On Fri, Mar 03, 2023 at 04:19:51PM +0100, Alexander Lobakin wrote: > From: Kees Cook <keescook@chromium.org> > Date: Thu, 2 Mar 2023 14:49:50 -0800 > > > Under CONFIG_FORTIFY_SOURCE, memcpy() will check the size of destination > > and source buffers. Defining kernel_headers_data as "char" would trip > > this check. Since these addresses are treated as byte arrays, define > > them as arrays (as done everywhere else). > > Yet another array-as-one-char, I wonder how many are still here... Yeah, good point. They do tend to stand out; we could find them: $ git grep 'extern char [^\*\[\( ]*;' arch/alpha/boot/bootp.c:extern char _end; arch/alpha/boot/bootpz.c:extern char _end; arch/alpha/boot/main.c: extern char _end; arch/arm/mach-rockchip/core.h:extern char rockchip_secondary_trampoline; arch/arm/mach-rockchip/core.h:extern char rockchip_secondary_trampoline_end; arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline; arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline_jump; arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline_end; arch/hexagon/include/uapi/asm/setup.h:extern char external_cmdline_buffer; arch/ia64/include/asm/smp.h:extern char no_int_routing; arch/ia64/kernel/process.c: extern char ia64_ret_from_clone; arch/mips/dec/prom/memory.c: extern char genexcept_early; arch/mips/kernel/traps.c: extern char except_vec3_generic; arch/mips/kernel/traps.c: extern char except_vec4; arch/mips/kernel/traps.c: extern char except_vec3_r4000; arch/mips/mm/c-octeon.c: extern char except_vec2_octeon; arch/parisc/boot/compressed/misc.c:extern char output_len; arch/parisc/boot/compressed/misc.c:extern char _startcode_end; arch/powerpc/include/asm/smp.h:extern char __secondary_hold; arch/s390/include/asm/kvm_host.h:extern char sie_exit; arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_enter_start; arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_enter_end; arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_leave_start; arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_leave_end; arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_enter_start; arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_enter_end; arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_leave_start; arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_leave_end; arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_enter_start; arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_enter_end; arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_leave_start; arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_leave_end; arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_enter_start; arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_enter_end; arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_leave_start; arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_leave_end; arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_enter_start; arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_enter_end; arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_leave_start; arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_leave_end; arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_enter_start; arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_enter_end; arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_resume_start; arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_resume_end; arch/x86/entry/vsyscall/vsyscall_64.c: extern char __vsyscall_page; arch/x86/include/asm/vvar.h:extern char __vvar_page; kernel/configs.c:extern char kernel_config_data; kernel/configs.c:extern char kernel_config_data_end; net/bpfilter/bpfilter_kern.c:extern char bpfilter_umh_start; net/bpfilter/bpfilter_kern.c:extern char bpfilter_umh_end; samples/bpf/task_fd_query_user.c: extern char __executable_start; tools/testing/selftests/kvm/lib/aarch64/processor.c: extern char vectors; tools/testing/selftests/x86/test_syscall_vdso.c:extern char int80; Of those, it looks like only a handful might trip FORTIFY: $ for i in $(git grep 'extern char [^\*\[\( ]*;' | grep -v boot/ | awk -F' ' '{print $NF}' | cut -d';' -f1); do git grep -E '(strcpy|memcpy|memset).*'"$i",; done arch/arm/mach-rockchip/platsmp.c: memcpy_toio(sram_base_addr, &rockchip_secondary_trampoline, trampoline_sz); arch/arm/mach-zynq/platsmp.c: memcpy_toio(zero, &zynq_secondary_trampoline, arch/mips/dec/prom/memory.c: memcpy((void *)(CKSEG0 + 0x80), &genexcept_early, 0x80); arch/sh/kernel/cpu/shmobile/pm.c: memcpy(vp, &sh_mobile_sleep_enter_start, n); arch/sh/kernel/cpu/shmobile/pm.c: memcpy(vp, &sh_mobile_sleep_resume_start, n); arch/arm64/mm/trans_pgd.c: memcpy(hyp_stub, &trans_pgd_stub_vectors, ARM64_VECTOR_TABLE_LEN);
From: Kees Cook <keescook@chromium.org> Date: Fri, 3 Mar 2023 12:36:09 -0800 > On Fri, Mar 03, 2023 at 04:19:51PM +0100, Alexander Lobakin wrote: >> From: Kees Cook <keescook@chromium.org> >> Date: Thu, 2 Mar 2023 14:49:50 -0800 >> >>> Under CONFIG_FORTIFY_SOURCE, memcpy() will check the size of destination >>> and source buffers. Defining kernel_headers_data as "char" would trip >>> this check. Since these addresses are treated as byte arrays, define >>> them as arrays (as done everywhere else). >> >> Yet another array-as-one-char, I wonder how many are still here... > > Yeah, good point. They do tend to stand out; we could find them: > > $ git grep 'extern char [^\*\[\( ]*;' > arch/alpha/boot/bootp.c:extern char _end; > arch/alpha/boot/bootpz.c:extern char _end; > arch/alpha/boot/main.c: extern char _end; > arch/arm/mach-rockchip/core.h:extern char rockchip_secondary_trampoline; > arch/arm/mach-rockchip/core.h:extern char rockchip_secondary_trampoline_end; > arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline; > arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline_jump; > arch/arm/mach-zynq/common.h:extern char zynq_secondary_trampoline_end; > arch/hexagon/include/uapi/asm/setup.h:extern char external_cmdline_buffer; > arch/ia64/include/asm/smp.h:extern char no_int_routing; > arch/ia64/kernel/process.c: extern char ia64_ret_from_clone; > arch/mips/dec/prom/memory.c: extern char genexcept_early; > arch/mips/kernel/traps.c: extern char except_vec3_generic; > arch/mips/kernel/traps.c: extern char except_vec4; > arch/mips/kernel/traps.c: extern char except_vec3_r4000; > arch/mips/mm/c-octeon.c: extern char except_vec2_octeon; > arch/parisc/boot/compressed/misc.c:extern char output_len; > arch/parisc/boot/compressed/misc.c:extern char _startcode_end; > arch/powerpc/include/asm/smp.h:extern char __secondary_hold; > arch/s390/include/asm/kvm_host.h:extern char sie_exit; > arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_enter_start; > arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_enter_end; > arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_leave_start; > arch/sh/boards/mach-ap325rxa/setup.c:extern char ap325rxa_sdram_leave_end; > arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_enter_start; > arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_enter_end; > arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_leave_start; > arch/sh/boards/mach-ecovec24/setup.c:extern char ecovec24_sdram_leave_end; > arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_enter_start; > arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_enter_end; > arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_leave_start; > arch/sh/boards/mach-kfr2r09/setup.c:extern char kfr2r09_sdram_leave_end; > arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_enter_start; > arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_enter_end; > arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_leave_start; > arch/sh/boards/mach-migor/setup.c:extern char migor_sdram_leave_end; > arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_enter_start; > arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_enter_end; > arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_leave_start; > arch/sh/boards/mach-se/7724/setup.c:extern char ms7724se_sdram_leave_end; > arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_enter_start; > arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_enter_end; > arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_resume_start; > arch/sh/kernel/cpu/shmobile/pm.c:extern char sh_mobile_sleep_resume_end; > arch/x86/entry/vsyscall/vsyscall_64.c: extern char __vsyscall_page; > arch/x86/include/asm/vvar.h:extern char __vvar_page; > kernel/configs.c:extern char kernel_config_data; > kernel/configs.c:extern char kernel_config_data_end; > net/bpfilter/bpfilter_kern.c:extern char bpfilter_umh_start; > net/bpfilter/bpfilter_kern.c:extern char bpfilter_umh_end; > samples/bpf/task_fd_query_user.c: extern char __executable_start; > tools/testing/selftests/kvm/lib/aarch64/processor.c: extern char vectors; > tools/testing/selftests/x86/test_syscall_vdso.c:extern char int80; > > Of those, it looks like only a handful might trip FORTIFY: > > $ for i in $(git grep 'extern char [^\*\[\( ]*;' | grep -v boot/ | awk -F' ' '{print $NF}' | cut -d';' -f1); do git grep -E '(strcpy|memcpy|memset).*'"$i",; done > arch/arm/mach-rockchip/platsmp.c: memcpy_toio(sram_base_addr, &rockchip_secondary_trampoline, trampoline_sz); > arch/arm/mach-zynq/platsmp.c: memcpy_toio(zero, &zynq_secondary_trampoline, > arch/mips/dec/prom/memory.c: memcpy((void *)(CKSEG0 + 0x80), &genexcept_early, 0x80); > arch/sh/kernel/cpu/shmobile/pm.c: memcpy(vp, &sh_mobile_sleep_enter_start, n); > arch/sh/kernel/cpu/shmobile/pm.c: memcpy(vp, &sh_mobile_sleep_resume_start, n); > arch/arm64/mm/trans_pgd.c: memcpy(hyp_stub, &trans_pgd_stub_vectors, ARM64_VECTOR_TABLE_LEN); > > This list looks much better than the first one :D I remember I caught a couple fortify bugs due to such array declaration on MIPS only when testing with `KCFLAGS=-O3`. The thing was that a pointer to such array-not-array was passed as a function argument and that function wasn't inlined on -O2. So I sometimes use this optlevel for sanity-checking the code :P Thanks, Olek
diff --git a/kernel/kheaders.c b/kernel/kheaders.c index 8f69772af77b..42163c9e94e5 100644 --- a/kernel/kheaders.c +++ b/kernel/kheaders.c @@ -26,15 +26,15 @@ asm ( " .popsection \n" ); -extern char kernel_headers_data; -extern char kernel_headers_data_end; +extern char kernel_headers_data[]; +extern char kernel_headers_data_end[]; static ssize_t ikheaders_read(struct file *file, struct kobject *kobj, struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len) { - memcpy(buf, &kernel_headers_data + off, len); + memcpy(buf, &kernel_headers_data[off], len); return len; } @@ -48,8 +48,8 @@ static struct bin_attribute kheaders_attr __ro_after_init = { static int __init ikheaders_init(void) { - kheaders_attr.size = (&kernel_headers_data_end - - &kernel_headers_data); + kheaders_attr.size = (kernel_headers_data_end - + kernel_headers_data); return sysfs_create_bin_file(kernel_kobj, &kheaders_attr); }