From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 C5BE3284B37 for ; Sat, 6 Jun 2026 15:10:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780758639; cv=none; b=ZIfPUDoHwsTYQOGvbSE6jUbSawZUUE/EhoohtcI63fqnXc1hZm+SqQsaukpv9zoGIViOyXaPXcVDAmAkH1ebLuvi0z0qgokje0m6QUDaWXM+10hx02bK3kPTZlPyL/uKSBKQuFZF8GFZ0iJ9CS3iFz8K6lPy/77zc3r0qxhNZ58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780758639; c=relaxed/simple; bh=7sa/5aDOfaPmf/uAo2DRuIB/gne7zOFu0FA8ZQ56WC8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=exZt8qxkO1v6Yc6aDCKpIJVMgMxsA9XzMyR0vtHE3PL7tdEYfckN5W/bC521axrhxVLqguS3bTNZWgzCusP6adxM9NL8oTzgluli0n5Dti5yRDVZDEob/5Mh7LxWpumo6OOLXEo5xCvYa+i/JJ5y9Cga9sdI/GCuCfajep5LYms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r0kHWuDi; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r0kHWuDi" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2c0b1a48855so217275ad.0 for ; Sat, 06 Jun 2026 08:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780758638; x=1781363438; 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=SH7p2r0XbIZkkYIzKa3j4SRiREgHnDdYKxXkuoiSFgk=; b=r0kHWuDico7L7Mqhhp/KBU3cWqbOgQgI6c8aIkn+PKLDD/6Bf49E4gYsznOq1xkwfB gJmWVqzNubKK/3qrbp65QKY4QmzXvfNInEl9+DxAc1WhK18Jz2x52210F/2haJO9lpqf UuBga7K+aJuQZtlb9WqMOAhkVmD2pN9V8YcD3wZ022121oTecRoUUvNdBdjPuOnzq5vW LPKZjvG41dbn1Tetd18YIB+eZoRE/noWCSGItlNjqDCKY2aYdrbsy6vWAwxQez5plIX/ rOuHrHV8jfIn2Jue03U//5humeJEUIDHUyiA4lK45w9CZqQH1dEUkC2n38T2sc+lu1+M 7X/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780758638; x=1781363438; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SH7p2r0XbIZkkYIzKa3j4SRiREgHnDdYKxXkuoiSFgk=; b=F+ECq4S0vu30ZJGXd0oKhiYcxf1+HLMx2WWdxm1txKm3hARrKHTo59TUTtzhnLXx7o RPaj9cPih0wih+Y1FogQ0In3/Rcd7E+tynq/8C+8JajuAH17dJ/tVpMpTcBJnbDbVrV2 jD++OgVVx408EG9kT0uFvlkZ8ma3TEw2rYrCh+kmqWrER4YscRYVCzluI6sPcopd928v kREkYDbQ/g8hZp2f1YE987ug/OdVlavsnJrY78FN+iaN8uxuXTSmLPAm7sZwLXJcJ3Ff 7RIuWWYJ59Y82BP24y/TgSqHoPAGDgPVlx9YuiWYXuXZ782sic2uRK48qs95kO9CakMu ZgrQ== X-Forwarded-Encrypted: i=1; AFNElJ88y2a8Moka5s3bf2ndo5URcHGiV2vVRaPvHzKdexQGDJkrKesn3ooPGaj2DJ4n/QUOkeOW4PMDPEen1PA=@vger.kernel.org X-Gm-Message-State: AOJu0YxO5WM5ttUa//yF9x+b7ueu/CDuPzi2Kf//VwwKhUMzJJaN6loy 6Fq1V5/r4DlZuT0IktjF+6W0dhlGCQG8lkpThzFAgT0v26YwcQPCS9OoqJkLUK6wcQ== X-Gm-Gg: Acq92OGYjH+n/ohqoyIpX6B1iLMvALrcrc3QtpFinE0jaXSrlpzbQgDuBk4IxFx3LFI EdPCvZZ9d2FnBY9yWU1Ifk3CmLHs6lYH5krkTdCOA8kd1m3TvM9S1F5FuVSBPhbxtXqmBcO/gJA s/f0I748H3xr/0uWGuRTxoOaujQkl4oUa3g8BTxHPLY1lCSNBXaOhhPuAPjjjFBATib9jdbUmXq SSoKTGMxJOAMJfnvP12yBQue55k4rPWG+4H1hOkkUmzu1m4g8014Sjn6kxYWIkl9mUQLhJFPGxg iHFpiZ2PceU46Lscsp1TSKb+hRVbJifMZ+TjaSqkGK/CNjy4V4NdMF3iyUs8Pn3kiLtJwyna5IV 4cdlXlUZMxQ1/WypUuQ0F8mqZlSjUZicp18g1lLV+xOhktB//iWOIzXiOFHItBp46b5ATAXppFp X7qQYHaPnlBNW7UM63gUhN10xBggmntqd9QXjK5cqfr0xBE6K0dVECLEHqfGDBlJL11hwLzN7MP dTQRlLfIlANMkHaOhblv8dFDT7OY+bPbVOXEfep7ODHMDk5CLceC42i X-Received: by 2002:a17:902:f708:b0:2c1:ee6e:be23 with SMTP id d9443c01a7336-2c1ee6ec5ebmr2652725ad.33.1780758637663; Sat, 06 Jun 2026 08:10:37 -0700 (PDT) Received: from google.com (112.174.16.34.bc.googleusercontent.com. [34.16.174.112]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c85df0b374fsm10852186a12.25.2026.06.06.08.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 08:10:36 -0700 (PDT) Date: Sat, 6 Jun 2026 15:10:33 +0000 From: Carlos Llamas To: Chris Mason Cc: gregkh@linuxfoundation.org, christian@brauner.io, aliceryhl@google.com, arve@android.com, tkjos@android.com, casey@schaufler-ca.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] binder: cache secctx size before release zeroes it Message-ID: References: <20260603174506.1957278-1-clm@meta.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: <20260603174506.1957278-1-clm@meta.com> On Wed, Jun 03, 2026 at 10:44:54AM -0700, Chris Mason wrote: > binder_transaction() bounds the scatter-gather buffer area with > sg_buf_end_offset and subtracts the aligned LSM context size because > the secctx is written at the tail of that area. The subtraction reads > lsmctx.len, but that field has already been cleared by the time the > line runs: > > security_secid_to_secctx(secid, &lsmctx) /* lsmctx.len set */ > lsmctx_aligned_size = ALIGN(lsmctx.len, sizeof(u64)) > extra_buffers_size += lsmctx_aligned_size > ... > security_release_secctx(&lsmctx) /* memset zeroes len */ > ... > sg_buf_end_offset = sg_buf_offset + extra_buffers_size > - ALIGN(lsmctx.len, sizeof(u64)) /* ALIGN(0,8) */ > > security_release_secctx() does memset(cp, 0, sizeof(*cp)), so lsmctx.len > reads back as 0 and the subtraction contributes nothing, leaving > sg_buf_end_offset too large by the aligned secctx size on every > transaction to a txn_security_ctx node. > > Each BINDER_TYPE_PTR object then derives buf_left = sg_buf_end_offset - > sg_buf_offset as the sole upper bound on its copy, so the inflated end > offset lets the copy run into the bytes that already hold the secctx. > > The aligned size must therefore be cached before release rather than > re-read from the now-cleared field. Fix by caching it in > lsmctx_aligned_size at function scope when it is first computed and > subtracting lsmctx_aligned_size instead of re-reading lsmctx.len after > release. Reuse the same value for the earlier buf_offset computation. > > Fixes: 6fba89813ccf ("lsm: ensure the correct LSM context releaser") > Cc: stable@vger.kernel.org > Assisted-by: kres:claude-opus-4-8 > Signed-off-by: Chris Mason > --- Thanks, Acked-by: Carlos Llamas