Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp59696pxb; Tue, 12 Jan 2021 20:05:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyftuZmAsNCQuvZfKb6zZL/JweJD5qgeVA/k6tUCpzYA6SYXHfAZSuNALY0Uz9td4GF1rc X-Received: by 2002:a05:6402:1386:: with SMTP id b6mr246311edv.42.1610510700258; Tue, 12 Jan 2021 20:05:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610510700; cv=none; d=google.com; s=arc-20160816; b=k874YO/ipGxxlG5xCuiP1WSnTkbBGSKImiR9aLXu/p6l8ugYrLZPesEXKjgc3PLFV1 PyGAUT9YVnbH6Bp8BIOXKkJsA6rIHyQnJwaCtLiOy0+mLTipCn6ECdQihm1dmYr9MBAv jIAHGxeH53PVtoUtVhIp6PLzaz5RoSqplgvLTwLTHLL9ANWhesxXoF1bIMQH55wLU/uR CIRxkuNjgmiYZK/UyYiFjmJOk5+tjs7IgIne4bqA76aP6+IeiVFcorJNzVqn6JmQVnUv y6bB06NlrJxCUoL12v+Gosuw82+oW84GXaKjxcgTa0NmpVEsjMwWOkUQAnqDlxxRr3gP 6ywQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=1LiS/Ah7gWBCj+VqG26e57TUr+FTn3EftEs4Z008F6g=; b=OVFssb/JjZXMCQgOoJnyPTqi6G6Iiaes7QCDEa/nCA4RvlpaKGvdMTK5VolitL6z4m 6inYt8G5OaLzqrQJK/OXlK/FOx9D4SSSwpUQxqlPj44olIQV6rDfxMUqlf7EO0NDrpKo epL78rJCQSZXVheVRRWsM+k0d5fsmNJ5C+DOF2yKpWUrjjm5z7ts7zq1fmBHQ7UsnOX6 4zZvLL9/mEvRr8lM2+VDEZLCz8MBEw2tknzcBgqsPHSVXeWhVJxg59rwNZMHBgP6zu/B DjJ37kmL5+LsLiX2BZw6j9tydVWCj+w5GuFnyL6UM4bT25g4ssW6EH1SMmRDBmVHC5qa /xvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Tte5vz34; 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 lt15si369725ejb.499.2021.01.12.20.04.37; Tue, 12 Jan 2021 20:05: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=@google.com header.s=20161025 header.b=Tte5vz34; 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 S2392359AbhALVgN (ORCPT + 99 others); Tue, 12 Jan 2021 16:36:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437134AbhALVRa (ORCPT ); Tue, 12 Jan 2021 16:17:30 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5133DC061575 for ; Tue, 12 Jan 2021 13:16:50 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id j1so2121780pld.3 for ; Tue, 12 Jan 2021 13:16:50 -0800 (PST) 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=1LiS/Ah7gWBCj+VqG26e57TUr+FTn3EftEs4Z008F6g=; b=Tte5vz34Ez295H9ux5RiqtzRXjKmLGKaImkiavOzuENuH8a2CsP3SmS92MtBal8eUp sYDUR+bThu/Q5yWFGkJvZ2OKhjN5KcIGfqgtA6GQl9braYM0IWn3jsvE/mLYMC1o03ge h6rq9fDZshnS8HfvQ6HP7G9TV6SXofpF0/1RWFQMsyIxwDl+ajLsVOIXj3/Z57NghYDd Dn6ca1dOeV51P6owuT+ORL/XRhoQJL1KJiQdjtLklX+tlJCBA3hXi8a9a/rP06MEVe6C TMTkhQ2IvCJYfLX6Y/4ZDCPSsECnId8AVHQ2pibJAbnDZOtBGQ+MNrgRKDQaVY65qwsT u1Ew== 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=1LiS/Ah7gWBCj+VqG26e57TUr+FTn3EftEs4Z008F6g=; b=QqZNhyy7pIGE55IMSRVHgfkSenP4iHH1nl65j80i2O2ddGYQ9Z5ETr7hqq9xCN7uTu Po0AA7x10v78M+m2KPhP1zXfb/c6OBfrZBHetarrxT+uI8GETaCMXlxPb0OWQ0Qu7hL6 ICDDFQocH3gAKbA2Ldt+GSC12HmvtphHdHxI5Vb/0OvR05yK83KTzQdJcfJutadA4WHC 9Kztc0xIxQXhzwXHiR/397dwT40nd91tfzjJtY42MEzWqBd2Ek9uCSnaVBLe6uGIiNHY IrXiU/A0Gdi6upu6Q+vrxY+teTP9rbvk3tC+S2XBdGk4aCwm6Qh0VDtNEZRny5ImMwa3 OVww== X-Gm-Message-State: AOAM532GfHsNNR47/Ho0iaKABoO9WVwdj76KkNaeVmtn3NE/9yyYYVKZ 0kUVaSeBbziEtGxREgMJArUlCbuGN2/lX5ckIBlVCQ== X-Received: by 2002:a17:90b:1087:: with SMTP id gj7mr1070271pjb.41.1610486209574; Tue, 12 Jan 2021 13:16:49 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Tue, 12 Jan 2021 22:16:38 +0100 Message-ID: Subject: Re: [PATCH 10/11] kasan: fix bug detection via ksize for HW_TAGS mode To: Marco Elver Cc: Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Andrew Morton , Will Deacon , Andrey Ryabinin , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 3:32 PM Marco Elver wrote: > > > +/* > > + * Unlike kasan_check_read/write(), kasan_check_byte() is performed even for > > + * the hardware tag-based mode that doesn't rely on compiler instrumentation. > > + */ > > We have too many check-functions, and the name needs to be more precise. > Intuitively, I would have thought this should have access-type, i.e. > read or write, effectively mirroring a normal access. > > Would kasan_check_byte_read() be better (and just not have a 'write' > variant because we do not need it)? This would restore ksize() closest > to what it was before (assuming reporting behaviour is fixed, too). > > void kasan_poison(const void *address, size_t size, u8 value); > > void kasan_unpoison(const void *address, size_t size); > > -bool kasan_check_invalid_free(void *addr); > > +bool kasan_check(const void *addr); > > Definitely prefer shorted names, but we're in the unfortunate situation > of having numerous kasan_check-functions, so we probably need to be more > precise. > > kasan_check() makes me think this also does reporting, but it does not > (it seems to only check the metadata for validity). > > The internal function could therefore be kasan_check_allocated() (it's > now the inverse of kasan_check_invalid_free()). Re: kasan_check_byte(): I think the _read suffix is only making the name longer. ksize() isn't checking that the memory is readable (or writable), it's checking that it's addressable. At least that's the intention of the annotation, so it makes sense to name it correspondingly despite the implementation. Having all kasan_check_*() functions both checking and reporting makes sense, so let's keep the kasan_check_ prefix. What isn't obvious from the name is that this function is present for every kasan mode. Maybe kasan_check_byte_always()? Although it also seems too long. But I'm OK with keeping kasan_check_byte(). Re kasan_check(): Here we can use Andrew's suggestion about the name being related to what the function returns. And also drop the kasan_check_ prefix as this function only does the checking. Let's use kasan_byte_accessible() instead of kasan_check(). > > +bool __kasan_check_byte(const void *address, unsigned long ip) > > +{ > > + if (!kasan_check(address)) { > > + kasan_report_invalid_free((void *)address, ip); > > This is strange: why does it report an invalid free? Should this be a > use-after-free? I think this could just call kasan_report(....) for 1 > byte, and we'd get the right report. Will fix in v2. Thanks!