Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1264658lqa; Mon, 29 Apr 2024 03:30:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbL0XeV5kxS+DLp1DxStM9twsCUIkvPIDqEDSvC0FyEkNg3y3QtdNQjthNhfVzl76wV/zQVVdeHv0f/8Q3ml3OQL54y1GwORax74pp8g== X-Google-Smtp-Source: AGHT+IFxM0XraYwtfmfPlgXv7XUB+xCM0fFu3kOLnOIohpCwI63G2rRb6xqefrTcdJvom2Zzdv1B X-Received: by 2002:a17:90b:1948:b0:29b:c9ac:c563 with SMTP id nk8-20020a17090b194800b0029bc9acc563mr8762755pjb.19.1714386643582; Mon, 29 Apr 2024 03:30:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714386643; cv=pass; d=google.com; s=arc-20160816; b=pYlcIUvL1cAi5lf1PUbsXE1enMPOIlKYmlbXIsZ6LWUrkKnq7XbSQZ2KnAxyi3CmKk gcGaKJtU8e5C9TXOjEHkoPfyvfDs2/ShCfBejkLziAaV/MUn1cH07gjJqXZHHmHn9POH TFX5TBwbfLuhoUMXjLFVShspnRh2NRzKgtNrcYBzCaQGRpUqrpZx/2eqNa5KqZBjp52g 3tQ58D978xcv0vA2kSyZtmqX4XSzs8ifLTf8feWAeBR2J78Bq8EtaOcyorWkZEdIVgdw 6K+OMmS2fup0JXbAGrg/Vb3Z/BRZRAUV7RCevhqwXm7yGijTiwe/XAjBnhjD4GvAJqiL bxTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2HfdH1jIH2/B+b7aR8d7pkmFhac9pK2yLLIIWF+ZffE=; fh=X1+NUGy47PdlVstw6gs9p28PoR9BbkwzcImpZ5KChXg=; b=gFkvGiV2amDuWw40rYO+dfXKz7RxTKiv8UNhRXbNy2j/cQ1fGPtbw9aTfBQrHzBBFq 9hqdxo5aS34elG0JW4FSIo1bNSyEPB/DqFijTwQlMt2auepxaFlBmXU100tr/n2QYqlP PIrBG9BTDLpBE3t2mnKm2M0Sz5WhQRHdKZijaOajCIdtidpEsn73p2CTXYC9DAAgHCwq e8ygfTL+jtqN59Tm4Kyn2p2P8izv/PEGqjACPf1wJJ4iM8DrCGchPMvr2VnTk7eIc/Ax dZJybU6+zGl9lDtZKbpr4nHjDxYY+ZZz0Zp7G3uM+dHHHw8SsQ3h6tfqQHbyJeJy70LN hecg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oh+QzXWO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-162056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p14-20020a17090a680e00b002a2949ce3b7si15640345pjj.181.2024.04.29.03.30.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 03:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oh+QzXWO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-162056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 313A0280D3B for ; Mon, 29 Apr 2024 10:30:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D69D6179AB; Mon, 29 Apr 2024 10:30:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="oh+QzXWO" Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B181848E for ; Mon, 29 Apr 2024 10:30:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714386636; cv=none; b=bLZQBSlKnLDqrBzytN/cBsPBjc8Y0AHwbSw2c8XGGvRHxQ1HTlBVua1lAAC9AojMxPz2DcqdAlfMoHfWIExwZhHCMf9liq5fNrP8juHhtjzZ5acxEN+vg//EHeCXvJ/X56b2nYBlR/AmkhtZbpyd/PUYJddYaOoBPNdzpi9jWzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714386636; c=relaxed/simple; bh=UbDQchwJ/5MpMWWetkzU6K8E2bg8wM9Cju7lJa1j2uM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oxyNHk12UYODaCpetcwg3vEkoV4CDXKycj4k4upUOpQ55ilVSL29RkaeYXxdZPjq954kU2eilCQkEN9AJKxmF2ja4mPIOy0up/k/5pIHbt9c2L6x+PzZm+WV+F2FURL4wwOuwpK4fYr48GX4uHQGh94EETR87jLFY8cGEIQyD1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=oh+QzXWO; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57222fc625aso4762336a12.3 for ; Mon, 29 Apr 2024 03:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714386633; x=1714991433; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=2HfdH1jIH2/B+b7aR8d7pkmFhac9pK2yLLIIWF+ZffE=; b=oh+QzXWO7GPG/rrPwOopWYzTXX2K94O0aR2QmPX5hnwa6PAiruuu1LwqbwxyBi2tDl c24hTVkZjHtL4x2t4LtP4zHrngUc1P4ZLGduv4q+ZvShcrxwEEJfJDPElZCOXUUFZDC6 ysrnI/7hMwdig0LCluG1GAKmGXXzzIz8qC7mQbf7MtGtTDJ6qceFduCpbEOUrJANs1W/ lR4j2xKX2nQITly/Kan9Ay2Y9V8f2n36PQYqaYyzBoF/U/HaimydTYnZa6p5hKGgDGvF 2GtQEF7Ai9iEwjN/Aw4ER++eGSbs4f76lK2lqC/l6z57Ox2r3Vy32cGLdiazQFcINDme MvKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714386633; x=1714991433; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2HfdH1jIH2/B+b7aR8d7pkmFhac9pK2yLLIIWF+ZffE=; b=rq3K+QGSKC3/VH0oc+JXdcCAq4WTGp/FT+dj8LsRzZigdzjnQX/CK68Wc/LPqRNKAR boWU1RUBLaq65UJqueTlb8f+QDcAN2U25/n3gJxw42P47Z/YcaVUJB6Vtj6q6Kld8US5 im44akxjYNH5saJCTVyrzrydvtRmh9iABSM1VxPbqB7yQUPI0d5bNXhh6UMspukaQxzD uj9r7cJA6bvpFqEwfYTX1/zwjrHGhkMWi6yAPClTfMmymfKaGy1Z2Z0cOaLrwbs7ib4w cizhQr8y4KnQeoFUqovwY30mqDqNkJopBib15rzFWiLRWFBujxlRxGOxqhJuseSUJnFs Mezw== X-Forwarded-Encrypted: i=1; AJvYcCWo97D7MUvXn/HXUGKAHniJchgIC102Py+2FxxQ8XbrMNZaVEt+WRMV0Xbv4s5iXRdxf1ZKvfdONkoO/IG7+dkrn2kbWBGubiraNKlG X-Gm-Message-State: AOJu0YxjIQxywVqtKDgI+xPA1ZolGcsbUFfOTAqNHG0xcAGzAgUn2pnf npR6lhIXWdIGcFuUcUGpOYegLBOlxihjteaMnUJwJIPFbvs9U+ogvgdKhvya6AY= X-Received: by 2002:a17:906:eca5:b0:a52:699e:f2b6 with SMTP id qh5-20020a170906eca500b00a52699ef2b6mr7846394ejb.74.1714386632555; Mon, 29 Apr 2024 03:30:32 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id bw13-20020a170906c1cd00b00a58de09fd92sm3080025ejb.27.2024.04.29.03.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 03:30:32 -0700 (PDT) Date: Mon, 29 Apr 2024 13:30:28 +0300 From: Dan Carpenter To: "Zhijian Li (Fujitsu)" Cc: "dave@stgolabs.net" , "jonathan.cameron@huawei.com" , "dave.jiang@intel.com" , "alison.schofield@intel.com" , "vishal.l.verma@intel.com" , "ira.weiny@intel.com" , "dan.j.williams@intel.com" , "linux-cxl@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 1/2] cxl/region: Fix potential invalid pointer dereference Message-ID: References: <20240429013154.368118-1-lizhijian@fujitsu.com> <18a295a2-b734-45dd-9c95-660a9e1f58e4@moroto.mountain> <576dccd9-1f8d-4c69-bc7f-497413b87b9d@fujitsu.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <576dccd9-1f8d-4c69-bc7f-497413b87b9d@fujitsu.com> On Mon, Apr 29, 2024 at 10:25:35AM +0000, Zhijian Li (Fujitsu) wrote: > > 3084 mutex_lock(&cxlrd->range_lock); > > 3085 region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa, > > 3086 match_region_by_range); > > 3087 if (!region_dev) { > > 3088 cxlr = construct_region(cxlrd, cxled); > > 3089 region_dev = &cxlr->dev; > > ^^^^^^^^^^^ > > This is not a dereference, it's just pointer math. In in this case it's > > the same as saying: > > > > region_dev = (void *)cxlr; > > > You are right, a equivalent code could be: > region_dev = ((char *)cxlr) + offsetof(struct cxl_region, dev); > > Correct. But offsetof() is zero. It's the same math that to_cxl_region() does. regards, dan carpenter