From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBC9CC61DA4 for ; Thu, 16 Mar 2023 00:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbjCPAXm (ORCPT ); Wed, 15 Mar 2023 20:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjCPAXk (ORCPT ); Wed, 15 Mar 2023 20:23:40 -0400 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC56C76161 for ; Wed, 15 Mar 2023 17:23:39 -0700 (PDT) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5416b0ab0ecso327877b3.6 for ; Wed, 15 Mar 2023 17:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678926219; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GBBdkxZAXRCi7TG8F08OVVEoAmrcMUusc/B0YVetYOs=; b=Z/UXxuRicb6SbI++I77ObBvfb4Xq8N5eh78ZITv/DxHwxkyLLqwIiLSRm321BtAU0c BoY3lU0ejWLOGqA/lrwZ5owhTaJ8ZwNVOAf5+BK8jO3UDYVMZuzzruZCkXM9Z7XwSgGv ZW3gijy+AzytGAeEUy9YXPWIoDlSK+lILpY+bYr9YMRrUgt8EH2mpYZ49XOAgIOT8YBf Y8jzz+NX6WFbS9A+afLgml5urKYxM35YdJ2Mzr6SY35fSiwRNuP8gx+QXTThHDYiwd1J CUfdvGriDgnoObUVPxujzyyTcpUMbB5f1uh+e9TnrrjZuZ4cg9T87ihRcyNl0U5YNzcT lc5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678926219; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GBBdkxZAXRCi7TG8F08OVVEoAmrcMUusc/B0YVetYOs=; b=NmSgT3p6vl1hYuV2P2Vs1eCu0FyynaxN4TBpE9V5tgbIg1rKFDygueS02RE9tmaswT oGxT2SQ7/63baxbtPy5vXnFH89Z/p2i38iEvhQZL9UxopHezdxHVS3W/ju6rAVGoaw6n hA/kmtKk1KLAXicHfcF35EOykZi8r2F/9QAkIaDVPdfqNzUTGWIRtfk6DHBWKXlziT9b cHFnpZ0MQFZC4nX681JzDf1ysZ95JD6cr7RAqGR7AghrUaml3IJrIzcdgiAhUY0fc0zw Cu0IMVBNk7IWn544eOMjmFxhhkUGwTkGWEsR8pMPf0NL8E/avzgrUjo/WTOca6xf1mAa HY4A== X-Gm-Message-State: AO0yUKUXbascKZCv/NQxKu5styGgeplNRsoQRR7DwUe4e91YdYmQPWw8 5uHgtEeQVpKTCZUdOd59hxO7O+7vjy/Y6j14KCH8jg== X-Google-Smtp-Source: AK7set9h2LELWGEgT1pyTaNqOLlbwZfDCBsbw+igJGEtXuscsdRBZeL6JKIYmyIBeJdNCu9fu885MfPwRPsPb6rJqqw= X-Received: by 2002:a81:b184:0:b0:53c:6fda:835f with SMTP id p126-20020a81b184000000b0053c6fda835fmr1054065ywh.0.1678926218853; Wed, 15 Mar 2023 17:23:38 -0700 (PDT) MIME-Version: 1.0 References: <20230315154245.3405750-1-edumazet@google.com> <20230315154245.3405750-2-edumazet@google.com> <20230315142841.3a2ac99a@kernel.org> In-Reply-To: From: Eric Dumazet Date: Wed, 15 Mar 2023 17:23:27 -0700 Message-ID: Subject: Re: [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk() To: Linus Torvalds Cc: Jakub Kicinski , "David S . Miller" , Paolo Abeni , David Ahern , netdev@vger.kernel.org, eric.dumazet@gmail.com, Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Mar 15, 2023 at 5:11=E2=80=AFPM Eric Dumazet = wrote: > > On Wed, Mar 15, 2023 at 5:02=E2=80=AFPM Linus Torvalds > wrote: > > > > On Wed, Mar 15, 2023 at 4:56=E2=80=AFPM Eric Dumazet wrote: > > > > > > container_of_const() does not detect this bug at compile time, does i= t ? > > > > > > struct sk_buff *skb =3D ...; > > > > > > struct inet_sk *inet =3D inet_sk(skb); > > > > You didn't actually test it, did you? > > I thought I did, sorry. I will spend more time on it. Oh I might have been fooled, because of course we can not use sk for the macro parameter name. -ENOTENOUGHSLEEP Basically something like this should work just fine diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 6eb8235be67f8b8265cd86782aed2b489e8850ee..caa20a9055310f5ef108f9b1bb4= 3214a3d598b9e 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -305,11 +305,7 @@ static inline struct sock *skb_to_full_sk(const struct sk_buff *skb) return sk_to_full_sk(skb->sk); } -#define inet_sk(sk) \ - _Generic(sk, \ - const struct sock * : ((const struct inet_sock *)(sk)), \ - struct sock * : ((struct inet_sock *)(sk)) \ - ) +#define inet_sk(ptr) container_of_const(ptr, struct inet_sock, sk) static inline void __inet_sk_copy_descendant(struct sock *sk_to, const struct sock *sk_from,