Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp71120pxk; Tue, 8 Sep 2020 22:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3ZjYme1SdEcHcb2LIoWWspfe8kAZr0CeHSn5kNrTVVSX69D8zIa1svfbEetkDPcp0hVDi X-Received: by 2002:a17:906:2786:: with SMTP id j6mr1882046ejc.73.1599629020514; Tue, 08 Sep 2020 22:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599629020; cv=none; d=google.com; s=arc-20160816; b=Ugk2UXx/0GKROX9ajJpLP33zZSqZgPw/A/1a0ghfY6TlJJG0JNMm/PaB2ZNpHmzno6 kR2KxM1awXiHNyI4AFZ3VYOL0MMdRDM6UamauK7Enfp6URGNX/x969BNJ8ApWEIO1Ptv 8xeFsMv3S+jFDRk2lET3d6kF/imS66J6ab3uCuzBEofk3ELvxfBlZyOe2PHg3QbxwiCN Gs3SlNr4zy6lP7V00IYnQ3B4J61OzufhzmjeTDJh21JgtVYye6H9UeVz/uAYAY0jcagw /aYZOr6xPF8kVMzFUCtkET2lItgRQMY178vM1LJeEehjo2t6iR0jDDiEiS3XH6nWCsjJ 06+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yrPV1rE9Q8aFyvmS+tTixzz0jds55x17Dqqm+UKxJfk=; b=uFDwmZPlPE8UUIq34fsFvBVe7A0rsTTFxwU1fUlLCksu1A8G5O3QMY92R1tJ9cRzAA x0EaLwrnXYEkfHUPg1SKsEXbaVIKkzYybxs8id37sUx/ziw/ZWTrm9vlx52XJ2xQ3VSS o8KXEUbvpNbEQOfMwbY55U30Od1caTQNbBRXoiilE53tLSxfxH8xdqDkMBuw0sBblubA RPnH8e5iwV287IzegzOtrAay8nxqfD1JxmT7/gbb4WD4G1fvL7Vj7f9lVslUmztNRz3h NsU5+eHveAirDmKv6feGPBb5eoNdWRaMbZSs0ItxVrRqEdv43zz7M3IN1yJXmtT99geh oASQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=upBkhNC7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si782636ejz.129.2020.09.08.22.23.17; Tue, 08 Sep 2020 22:23:40 -0700 (PDT) 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=@google.com header.s=20161025 header.b=upBkhNC7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726111AbgIIFUl (ORCPT + 99 others); Wed, 9 Sep 2020 01:20:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbgIIFUi (ORCPT ); Wed, 9 Sep 2020 01:20:38 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E670DC061573 for ; Tue, 8 Sep 2020 22:20:37 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id f11so942419qvw.3 for ; Tue, 08 Sep 2020 22:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yrPV1rE9Q8aFyvmS+tTixzz0jds55x17Dqqm+UKxJfk=; b=upBkhNC7/CwbfMP4grgGeEXnkcrY+L6uUNuGtg8ZkXR9wUURcKAn3g8KxYNYXGCbAq jV2vNLvdq+QkpIsvAb19gqCgcuie1X/DnNCMSJOFa3AMohDx2XEgXANsN2aK2L0hGkja cPniJ5Xf3CA9u2Sv6cqgqCf6XVLLlnMv9aey8a0Zc4oI5x/4v2Tv2a6ZhlzpBDu/h1XY wK1Ibqq1QogOwmuaM7N0x++nBWEO5dYt4x0eQ2CxcNW6Z8OJFs2IDaHZI8oF8PTagTnk s8FTymby006ZOPUna230UFFaHRpHRrS78DMzEclKul1vSuVT9nOPOB676uCRiH1nrhtf B1DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yrPV1rE9Q8aFyvmS+tTixzz0jds55x17Dqqm+UKxJfk=; b=Kc3AqSJG0o9MdzIIUW4bMD6+90ubx3Mu3CBGCfaPikFrt7ZjT5BizA4yn/ajE6gshl yTK7/UNXICj6N8i17+G5lKJgHQc68j1H/cgt3gtRf3PBEO9Jwfb7ctolDOL8FMWv2zkz 8BQyBoPLJTYSsoTTmeSoljDZBQXOBQyJaFS/3/zKQrLWDZhlSxOpU0uz/TBk5mknCCB+ oTyS1UwL/WXAdVrHF2Nr5ieZYN9dyKj0KrX9Vn2DxoZjAmVmgAlHScoK6Mwgqu+5SVEv ea3yGYgjxSeaGwXhj52vwJObVJ8qvXfG/ULKSqhbjtcxEprVuwY/fEJ4Ed8h+YTINpMk OxCQ== X-Gm-Message-State: AOAM530uw60M2tYlJrqlb5k1PDjTM7Du/PzqAxb4KQCWLZQqQTWuCvKx BGU1oZGih0H27yXgC4zp5TkZnPskHdFyGo+4Yt7mPA== X-Received: by 2002:a05:6214:7a1:: with SMTP id v1mr2544395qvz.19.1599628835784; Tue, 08 Sep 2020 22:20:35 -0700 (PDT) MIME-Version: 1.0 References: <20200905222323.1408968-1-nivedita@alum.mit.edu> <20200905222323.1408968-2-nivedita@alum.mit.edu> <202009081021.8E5957A1F@keescook> <20200908184003.GA4164124@rani.riverdale.lan> In-Reply-To: <20200908184003.GA4164124@rani.riverdale.lan> From: Dmitry Vyukov Date: Wed, 9 Sep 2020 07:20:24 +0200 Message-ID: Subject: Re: [RFC PATCH 1/2] lib/string: Disable instrumentation To: Arvind Sankar Cc: Kees Cook , Marco Elver , "the arch/x86 maintainers" , kasan-dev , LKML , Andrey Konovalov , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 8, 2020 at 8:40 PM Arvind Sankar wrote: > > On Tue, Sep 08, 2020 at 10:21:32AM -0700, Kees Cook wrote: > > On Tue, Sep 08, 2020 at 11:39:11AM +0200, Marco Elver wrote: > > > On Sun, 6 Sep 2020 at 00:23, Arvind Sankar wrote: > > > > > > > > String functions can be useful in early boot, but using instrumented > > > > versions can be problematic: eg on x86, some of the early boot code is > > > > executing out of an identity mapping rather than the kernel virtual > > > > addresses. Accessing any global variables at this point will lead to a > > > > crash. > > > > > > > > > > Ouch. > > > > > > We have found manifestations of bugs in lib/string.c functions, e.g.: > > > https://groups.google.com/forum/#!msg/syzkaller-bugs/atbKWcFqE9s/x7AtoVoBAgAJ > > > https://groups.google.com/forum/#!msg/syzkaller-bugs/iGBUm-FDhkM/chl05uEgBAAJ > > > > > > Is there any way this can be avoided? > > > > Agreed: I would like to keep this instrumentation; it's a common place > > to find bugs, security issues, etc. > > > > -- > > Kees Cook > > Ok, understood. I'll revise to open-code the strscpy instead. > > Is instrumentation supported on x86-32? load_ucode_bsp() on 32-bit is > called before paging is enabled, and load_ucode_bsp() itself, along with > eg lib/earlycpio and lib/string that it uses, don't have anything to > disable instrumentation. kcov, kasan, kcsan are unsupported already on > 32-bit, but the others like gcov and PROFILE_ALL_BRANCHES look like they > would just cause a crash if microcode loading is enabled. I agree we should not disable instrumentation of such common functions. Instead of open-coding these functions maybe we could produce both instrumented and non-instrumented versions from the same source implementation. Namely, place implementation in a header function with always_inline attribute and include it from 2 source files, one with instrumentation enabled and another with instrumentation disabled. This way we could produce strscpy (instrumented) and __strscpy (non-instrumented) from the same source.