Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp776185pxb; Wed, 25 Aug 2021 15:04:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybU9mgW37qowwLrAFlgTb9WDG/7RAVkBA2Vhs1GaJwm/QCSvrUU2vXcZVlgtQ1k5Jvv3Oa X-Received: by 2002:a05:6638:370a:: with SMTP id k10mr594233jav.20.1629929079306; Wed, 25 Aug 2021 15:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629929079; cv=none; d=google.com; s=arc-20160816; b=CbX5xSxx8OBNrBPDYMqjkzXlZdcCcVDf7xTNy66si0PJFp+GUn5Ar5B6Ubk48uMvoX aNWIt8KjELXgeN+yXOQdnqXfnK9hL7bmohgQBWiKOb1JpFUjwPaH8cLW0SSNttc/4IqI jvBJm8lEv31wy5qmaQFjjqD00X+viAro0GHMzOzFrm0ptogyqG+6mbH/ClxUHX7Rl0X7 OgJXqR2Z2sktOHaP9Ec1K29guu6qt6poZgTox0rwMehbLjaZia3eySj9w2OZg0riUqB9 P0AWTcTnOhryPaq3djLozo6p3uh56NBTjP3W/K9GmCq2z7uZYtTc/SoX6pz2PzCYQKFe s05Q== 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=Ap07zgvRCzHUWZsKzTqV0nv5eVeNrhiykOkW+2Q+N8I=; b=K4IrckA+zNuTuTA4znotga8q0x8ph8wDVbW6Wv5PQrj9KlqhLe8f0LVfkrNqI/DKlt 89sbwhImGHKIT2+5qRVzNXDOaNajr6WICF8R6W10iarF2MQgt06kMgzQPf0dG+0rpQul 9gxpGrlF7e42ibfkt9nY2jS0E3fd1thpGpU1eeKI0L1aATVshY4KhH9J0gFNzxYCJUz+ s1aaDp7AieaBzLPom+75GraokRtenT2Anpildikp0BbuuQvWxxMLwFhkVXHSsRBmm9TE mJUyekKnvP0EdWeVS8cLZ2m5lNR/WoyL9Z4VW+FwbbDuYChNTy+hmf+3g4vBPfMYiPJ9 X33g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=V0RfDdAy; 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 r11si1379475ill.21.2021.08.25.15.04.27; Wed, 25 Aug 2021 15:04:39 -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=V0RfDdAy; 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 S232135AbhHYWCz (ORCPT + 99 others); Wed, 25 Aug 2021 18:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbhHYWCy (ORCPT ); Wed, 25 Aug 2021 18:02:54 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F8A4C061757 for ; Wed, 25 Aug 2021 15:02:08 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id y34so1978125lfa.8 for ; Wed, 25 Aug 2021 15:02:08 -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=Ap07zgvRCzHUWZsKzTqV0nv5eVeNrhiykOkW+2Q+N8I=; b=V0RfDdAyEknz5KXI21deyJWGKBtldhdU7eYU32v3+FYtF8NzVK6ypPcrEQF8iGVh9+ R31/nL49iM2YuRMj6y07FYcnclwCqu87K4SCTWIdrCiyF816igVvCdfHYrfhyJ+UMKZJ YrIH5Sd3c7JRcix5m4U4SC4LSMyIbi24SUN22kt6fPeCw9xxYZe1jh0C2Aqi/HH0Tq5l K+1tLSG8Uzo4O2xuhUFeKcfFkgWa8dmjcF24ogJxzOUGVIddLld72otsgtWnMrEgJajR KrTIFh/vHsTkdSwzHCZwABYf8Li+J/BY75/krxwgZCKkUKe9uSRWfpqG3hKooSdUFzhU WbaA== 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=Ap07zgvRCzHUWZsKzTqV0nv5eVeNrhiykOkW+2Q+N8I=; b=P9tgIt8gptqz5Oue1ETh/KwPqm7QQ2T53Fcp9Md+GnsAS5QZ9q8y86d3JddCSOt3if m7bCozp+9aTwAjJWq1rCl8fmT9m9gbjSOUBb23xetdwjK9u9ecPFjLoqoHnZ6ruH1ljV VVw9bhAY+PSvcRTAL1KB1pXQ1nnkduWncOtpFnQN+uoH+T/vPoiaNHTevXbQcBlayESU k6BcyM8aKoP59z/LIHax6Eg1zzHWWcn9MsUdrgz5nYoq/759xDTbIJ3uJbc9lea/0/Cf 54ZShfbeIBsFk1JL0DhHjp5wpNDF2NZ9Roy/wcuq1WzE9DXRQ7MPhNwwh+AC7X/ZDU9y IUVw== X-Gm-Message-State: AOAM532n6nREhwn1vrjHfrnb1nQg+MeGj+IidSYthpJ+N0jEGZLGUEOy 2UJ9fvQpJ2VCFH/7SOQaS0RbQxgOxMV2U38yt3tVv5OlA+mv6Q== X-Received: by 2002:a19:f017:: with SMTP id p23mr190205lfc.547.1629928926500; Wed, 25 Aug 2021 15:02:06 -0700 (PDT) MIME-Version: 1.0 References: <20210822075122.864511-1-keescook@chromium.org> <20210822075122.864511-19-keescook@chromium.org> In-Reply-To: <20210822075122.864511-19-keescook@chromium.org> From: Nick Desaulniers Date: Wed, 25 Aug 2021 15:01:54 -0700 Message-ID: Subject: Re: [PATCH for-next 18/25] fortify: Prepare to improve strnlen() and strlen() warnings To: Kees Cook Cc: linux-kernel@vger.kernel.org, Francis Laniel , Rasmus Villemoes , Daniel Micay , Bart Van Assche , David Gow , linux-mm@kvack.org, clang-built-linux@googlegroups.com, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 22, 2021 at 12:57 AM Kees Cook wrote: > > In order to have strlen() use fortified strnlen() internally, swap their > positions in the source. Doing this as part of later changes makes > review difficult, so reoroder it here; no code changes. > > Cc: Francis Laniel > Signed-off-by: Kees Cook Reviewed-by: Nick Desaulniers > --- > include/linux/fortify-string.h | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h > index 68bc5978d916..a3cb1d9aacce 100644 > --- a/include/linux/fortify-string.h > +++ b/include/linux/fortify-string.h > @@ -56,6 +56,17 @@ __FORTIFY_INLINE char *strcat(char *p, const char *q) > return p; > } > > +extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen); > +__FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen) > +{ > + size_t p_size = __builtin_object_size(p, 1); > + __kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size); > + > + if (p_size <= ret && maxlen != ret) > + fortify_panic(__func__); > + return ret; > +} > + > __FORTIFY_INLINE __kernel_size_t strlen(const char *p) > { > __kernel_size_t ret; > @@ -71,17 +82,6 @@ __FORTIFY_INLINE __kernel_size_t strlen(const char *p) > return ret; > } > > -extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen); > -__FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen) > -{ > - size_t p_size = __builtin_object_size(p, 1); > - __kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size); > - > - if (p_size <= ret && maxlen != ret) > - fortify_panic(__func__); > - return ret; > -} > - > /* defined after fortified strlen to reuse it */ > extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy); > __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size) > -- > 2.30.2 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210822075122.864511-19-keescook%40chromium.org. -- Thanks, ~Nick Desaulniers