Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2140919rdb; Mon, 20 Nov 2023 03:16:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLkNoSb27V4RuJoC/OVt+UuPGHx2p95kdNHeaKJTYJQG08B0GPgEK0jnA8lN7J1cmMiLv9 X-Received: by 2002:a05:6a20:6a24:b0:187:44c0:d32b with SMTP id p36-20020a056a206a2400b0018744c0d32bmr5394927pzk.57.1700478987408; Mon, 20 Nov 2023 03:16:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700478987; cv=none; d=google.com; s=arc-20160816; b=xRR/UZcIAjbAnuxsxxl6VA2VhoVovyqnOzoHWlXODDX5jpkJQIC6pd7zSEx4DQzOT5 /tvOoMYySgrVrYFTalvg4V/YQE1rL7m7ersb4vakwJHWTIH1xUPl/WYq1AqhKIhiTtI2 RlOSId2BWyzMdV9dXFZtD905/rnmOjizLke+mDfYqvSOXZo8kJUGUbX5AHDVS2jTZF8M AQmWIpfCUguaH1CTLLrQMMTUrdyHhhy+bCSKZOkqfkEyQB4IqFLJ2NQTg4cjD/I+3kmf ECiNudyaDKJYtzzJ9kCEUv7ob7FT0BcTeX8pW2ojtaolj5ACRwdbb8dFbCZFooYYaJuU rdzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VGvdee3TQIpF1SI724cXO2Msx6guU5EDf9Sws5t+jG4=; fh=+Rin79kmEaAxQ6fWq4K0kM6s+jD7RLKlvtYJ9f/m2YQ=; b=rHXLa4XyybbWcxMbBI3JYpJHUwW3L0H7yLG+qmGPF6huYVqoo9LRIILmYheb4d2lVl +TkoAhXL8NxCg8uAb7vSIFIBWCvHtdd3/U6+kMT+/hGpTDG1kwvCQ5RuSJBd+L0o0i6M PQIT/9b6Rhuc4+uxup+QjOM+lB3xJ73elPN8f5fRlHT3EPOfrZM9PjxQ9da4lAwxqeag 8ZZRGRMPCYfXAnqy8K4uW4XsT3plY3MoqEtk4vt/rnT6j5Dpg3fzlXjrPP0acXxxJqIk I4SCuIgy8IilNMWOoNnPUGjH4oOEzfnWQ2ETtDzODVj/hYHlj7qXRpdaPKE7ZufQdr2R PGHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YbmJ7QrQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h9-20020a17090acf0900b002849048f576si5392992pju.148.2023.11.20.03.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:16:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YbmJ7QrQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7D0DD808D482; Mon, 20 Nov 2023 03:16:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbjKTLPz (ORCPT + 99 others); Mon, 20 Nov 2023 06:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233282AbjKTLPa (ORCPT ); Mon, 20 Nov 2023 06:15:30 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D86BD69 for ; Mon, 20 Nov 2023 03:15:23 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c6b30aca06so51573041fa.3 for ; Mon, 20 Nov 2023 03:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700478921; x=1701083721; darn=vger.kernel.org; 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=VGvdee3TQIpF1SI724cXO2Msx6guU5EDf9Sws5t+jG4=; b=YbmJ7QrQrfj/G1mNLxxa/icKwO9bmyfbl2z7ikDSTQ8ib6FOXwTN5/YG4QqlWGazJp LMS4xh0L34z02iBlPloGfFX8yidBYxRxAE/bI9C5dLaa8YuOOHS2nLraYjWpOdJKvEQd 0yOSpfQ2q+NE8uIEqYemxXuPYdgb9SQcF11wGib5ThrMT2h/kYt5MyASLOzpRaCpI+Dp v+ScGKd3o9IHVsR9xWCgm4OB+o4236i3SpS2deb806GWvS3kp8acZ3J0ejGBjc+AAIgG e5Rg7NvYE8QTKU+9x9J7CLXEveCycGFL5Az4twBf/LDIZujrm/rF4g0uX9j4q5oKj4TZ WFUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700478921; x=1701083721; 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=VGvdee3TQIpF1SI724cXO2Msx6guU5EDf9Sws5t+jG4=; b=Q17a0dLQYK4Mnqfeav3TdWQW8/zmlEEbT9QCImdNmWVws7dMikZ2AXzevPDjzoCuGQ TZdcJzZgH9a3HJZHaVgcNDZJIxjrj4WUFinRpEb5azxu0f65RH/rGjkiN/xUBw5CluNK n887cA4Jw73QvBERuxC9P0zNwjMb1bdrdUTCSA4+NQIXuwnnn4bbzoVMW9UMesscoSjR OiZlV3netyX6L//AgG/BdWPJBFWmqtY1tF+AnGeIko4W7Wn4aP48ykQdUnZMnjKjDMVg zzG6jbUa5iSo4IvWvTRv98dnklRsJ+ROnkwwknrUojDfZ0DRtkeRGl4s1SsmD53xouOv V96A== X-Gm-Message-State: AOJu0YxLRDxc9SakyzjjK1qez1ennS1KTGahdnBX0sOTrSaXxUnSZc2u rueVvzvarwhn1yTAD5hlZJWFlUgf21uZS5XmGVg= X-Received: by 2002:a2e:bea0:0:b0:2c5:56b:cbcb with SMTP id a32-20020a2ebea0000000b002c5056bcbcbmr5989090ljr.9.1700478921255; Mon, 20 Nov 2023 03:15:21 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> <20231119194740.94101-2-ryncsn@gmail.com> In-Reply-To: From: Kairui Song Date: Mon, 20 Nov 2023 19:14:59 +0800 Message-ID: Subject: Re: [PATCH 01/24] mm/swap: fix a potential undefined behavior issue To: Chris Li Cc: Matthew Wilcox , linux-mm , Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Michal Hocko , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:16:17 -0800 (PST) Chris Li =E4=BA=8E2023=E5=B9=B411=E6=9C=8820=E6=97=A5= =E5=91=A8=E4=B8=80 11:36=E5=86=99=E9=81=93=EF=BC=9A > > Hi Kairui, > > On Sun, Nov 19, 2023 at 12:55=E2=80=AFPM Matthew Wilcox wrote: > > > > On Mon, Nov 20, 2023 at 03:47:17AM +0800, Kairui Song wrote: > > > From: Kairui Song > > > > > > When folio is NULL, taking the address of its struct member is an > > > undefined behavior, the UB is caused by applying -> operator > > I think dereferencing the NULL pointer is undefined behavior. There is > no dereferencing here. It is just pointer arithmetic of NULL pointers, > which is adding offset of page to the NULL pointer, you got NULL. > > > > won't lead to a real issue, still better to fix it, also makes the > > > code less error-prone, when folio is NULL, page is also NULL, > > > instead of a meanless offset value. > > I consider your reasoning is invalid. NULL pointer arithmetic should > be legal. This patch is not needed. > > Chris Hi, Chris and Matthew. Thanks for the comments. Right, it's just a language syntax level thing, since "->" have a higher priority, so in the syntax level it is doing a member access first, then take the address. By C definition member access should not happen if the object is invalid (NULL). Only a hypothesis problem on paper... This is indeed not needed since in reality it's just pointer arithmetic. I'm OK dropping this.