Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp382338pxk; Fri, 11 Sep 2020 09:24:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhm2RR8p+tgc6hnQVkTvF6vME1POf0sAjyNKlkTS09xFtBQZEo/WNlFKud14qOcIgzjj7a X-Received: by 2002:aa7:c70a:: with SMTP id i10mr2999339edq.218.1599841475771; Fri, 11 Sep 2020 09:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599841475; cv=none; d=google.com; s=arc-20160816; b=BYHPK2vZjpdWnDFZlRXp5h9Xc9c8M4/+YgBkr5U+IW1ZEW7EncD3aRmQBLX3/dFzoG LK18zk9eL1RaSl4GiYFFmLTtV2KcF94+JWwtuB4dLKEkfKeJ9PSK/oiF1S+o+2N6chIV y74a+3Zo+aWqU896xX/XTQqJiqyWoQEJFFqCrJgV915iWmQVTqEzO2fX20+QDViHa02S KvGJdrIkQWjVwSHGbqgK9I9m763k0NxmhNr7utSoSgTAaUHgjuqNnXkYePRqbnDjBfN0 57VHjMLMazW87FBM2BsZs7DY9CiD89DpDynIn4nORdOPh0HNX9A5Tt3TwNOwEcglGg44 Lh7A== 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=evNZKysAyJVDJFT66khLohp3xUs13A1xSWcEfi9b540=; b=rNMZqPSmXsXQ0ad9OrDY2lP8Wm0fNME2InAIHxdBDc4MkOV/NA3CNZa/PyhDoEsFZP kvoOiFnzkYH87hE1sk9DzafJ0GvOELjPiDqOAZ4Uofy5AwpDUFXVau7YmcwZpDypHvms 5g/QFOjE92GtBV++UqdWQGA+eV3JR06f9zIGuh4i31+Ip7I+8ZjAsAicZ+yq7cdAZmGQ sf5/WgPLd+l7Dum4EsWs64Y3qn/yu61hGALh2jXbCrQ3YyXKCH446HoV8Nf83Dwp/MWl +hoLSCFesOT6Wv4GJu9aDcn2mFsXB5VgDUhH02pPyfoMLJUNcUm55CNfLB/cuUkGegd3 nVKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ae4tquuk; 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 g16si1640665ejf.211.2020.09.11.09.24.12; Fri, 11 Sep 2020 09:24:35 -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=Ae4tquuk; 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 S1726504AbgIKQWr (ORCPT + 99 others); Fri, 11 Sep 2020 12:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbgIKQWd (ORCPT ); Fri, 11 Sep 2020 12:22:33 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B54EC0613ED for ; Fri, 11 Sep 2020 09:22:32 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id r7so14520605ejs.11 for ; Fri, 11 Sep 2020 09:22:32 -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=evNZKysAyJVDJFT66khLohp3xUs13A1xSWcEfi9b540=; b=Ae4tquukEefgUlPmUmJU0RsPNNyjRmp/EcJwNrsDA4qCmFhdDh9bYbZ7o/pXQ7tnT4 svI/zhr2xDJ83F4ISMrwM3VLNLJGxaT9vhQrAE/9eDcRATsuHPM5THKfI9WzUCyJGKWC hNGME51ilNarXtOPN2bD5Ve9/meaJCLFgBJF/TZwW2ufT/quianqVNX4Gbk47G+RpJZc pZwL8/KHBuHRDv8Qujoba+Ef9Jb/LVnmsjpKi8BwAcGrQvalpwjdeyzmyN2udZtQ4Pb3 i3lHMW7qaKFoCp+cM8dKpFBDGLFeYk5c46WtvzAtz9fa9GiR1M4cfxsbexzvnHOL33yW 4i+A== 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=evNZKysAyJVDJFT66khLohp3xUs13A1xSWcEfi9b540=; b=cJG1ZnT1IbCkPutB3AG9uKszbEXGC96RwJa3/A3WUcW+hSHzTZthFbFfDbain7GW1h rYcJ0d7tWMvxSoBI+us/D8fNJNHGxfg0cD4FEllNhk+kGmDkv6kxJqBUwEO2i3Llmxtg 25N4vblnIxKSAmLt01XHQ2NtANouT5X+aGtDAvnYSN3Gl5rz4rTVJMiCnbrWLJDtzwg2 Q/BibLvwywxKiEUtX46JV7QEPbFKm2pDWshfdsFm4qn+WDPe4DaDWOYjJQVRo+DF1d2r lece2g7qLiPOoTGZQY9UNCxyfsZoG+aIx265j11C/8BeiICjmSZXl2ofRtLYwxEa2FIG N36g== X-Gm-Message-State: AOAM533fhYaj4Vtg7/dNFQm+kAMoYhaRGiEOqqbuXaM7QV7ECaMq5LTD ZIYQ+DZO8B1O6tDoERXUjH6fxEVtt7MVMUUagR7smg== X-Received: by 2002:a17:906:a0c2:: with SMTP id bh2mr2837607ejb.493.1599841351050; Fri, 11 Sep 2020 09:22:31 -0700 (PDT) MIME-Version: 1.0 References: <20200910134802.3160311-1-lenaptr@google.com> In-Reply-To: From: Jann Horn Date: Fri, 11 Sep 2020 18:22:04 +0200 Message-ID: Subject: Re: [PATCH] sched.h: drop in_ubsan field when UBSAN is in trap mode To: Elena Petrova Cc: Kernel Hardening , kernel list , Kees Cook , Andrew Morton 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 Fri, Sep 11, 2020 at 5:15 PM Elena Petrova wrote: > On Thu, 10 Sep 2020 at 20:35, Jann Horn wrote: > > On Thu, Sep 10, 2020 at 3:48 PM Elena Petrova wrote: > > > in_ubsan field of task_struct is only used in lib/ubsan.c, which in its > > > turn is used only `ifneq ($(CONFIG_UBSAN_TRAP),y)`. > > > > > > Removing unnecessary field from a task_struct will help preserve the > > > ABI between vanilla and CONFIG_UBSAN_TRAP'ed kernels. In particular, > > > this will help enabling bounds sanitizer transparently for Android's > > > GKI. > > > > The diff looks reasonable to me, but I'm curious about the > > justification in the commit message: > > > > Is the intent here that you want to be able to build a module without > > CONFIG_UBSAN and load it into a kernel that is built with > > CONFIG_UBSAN? Or the inverse? > > The former. But more precisely, with GKI Google gives a promise, that > when certain GKI is released, i.e. at 4.19, its ABI will never ever > change (or, perhaps only change with Android release), Really? How does that work when a kernel update needs to add elements to existing structs that are part of that "ABI"? Especially when those structs have something at the end that's variable-length (like task_struct) or they're embedded in something else? Maybe you should've done something like BPF's CORE if you really want to do something like that, teaching the compiler to generate relocations for struct offsets... > so vendor modules could have an independent development lifecycle. And > this patch, when backported, will help enable boundsan on kernels > where ABI has already been frozen. > > > Does this mean that in the future, gating new exported functions, or > > new struct fields, on CONFIG_UBSAN (independent of whether > > CONFIG_UBSAN_TRAP is set) will break Android? > > I don't understand what you mean here, sorry. Let's assume that at a later point, someone wants to track for each process how many UBSAN errors that process has seen so far. And maybe at that point, we have error recovery support in trap mode. So that person sends a patch that, among other things, adds something like this to task_struct: #ifdef CONFIG_UBSAN unsigned int ubsan_errors_seen; #endif If that patch lands, ABI compatibility between UBSAN=y&&UBSAN_TRAP=y and UBSAN=n will break again. I believe that it should normally be possible to add stuff like #ifdef CONFIG_ #endif to an existing kernel struct without breaking anything (outside UAPI headers and such). Your patch assumes that that won't happen for CONFIG_UBSAN. > > If you really want to do this, and using alternatives to patch out the > > ubsan instructions is not an option, I wonder whether it would be more > > reasonable to at least add a configuration where CONFIG_UBSAN is > > enabled but the compiler flag is not actually set. Then you could > > unconditionally build that android kernel and its modules with that > > config option, and wouldn't have to worry about structure size issues, > > dependencies on undefined symbols and so on. > > Such setup might be confusing for developers. Yeah, but I think that that's still cleaner than assuming that some normal kernel flag won't change struct layouts... Anyway, the diff itself looks reasonable to me (although I dislike the commit message), but don't be surprised if this "ABI" is broken again in the future. > We were considering > something similar: to keep the in_ubsan field regardless of the > CONFIG_UBSAN option. But since non-trap mode is unlikely to be used on > production devices due to size and performance overheads, I think it's > better to just get rid of an unused field, rather than balloon > task_struct. > > Cheers, > *lenaptr