From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 F413720DD76 for ; Fri, 10 Jan 2025 16:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736527416; cv=none; b=lyLXuZfus4JK3nE3b7yoPlaVsS+c8uFlTnnFjqv4I+/qRNtz+zr5Vak07bPDezKUC4xmtK6K/5lqE9Tgdmjy0UIyCgBPbgJCkX57OjlY1HQxHrWGQqVgrgt4zwTQ9taVIcT6EZyU7TtRclwg6cyBUfTXVhT18yiMpgGvvz5zc1Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736527416; c=relaxed/simple; bh=MWt2KSgXU/y4OdP9JtwCMJuE7V9BgYVBW01blZaNBBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pFitQ7bCxHu6fDGfkNB9CKbiT0fXHcHUBHqiFoKzIX4OSM785KqEI/wcRS3BVILheAV0pEUT0GraDOyOaBEqPWa6XupD5oShxM0sACJhsuY7Oj5C4BlSHLKM7K/s5h+tKHttA30/zbZNN64KGwlWrT3ohqd4BODnDp9hRlEn+Rk= 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=mzmmrava; arc=none smtp.client-ip=209.85.214.181 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="mzmmrava" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-215740b7fb8so161705ad.0 for ; Fri, 10 Jan 2025 08:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736527413; x=1737132213; 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=24Dc1ozbi/clwrekfep1mnhCPerumrP3eLe3i+hSGqk=; b=mzmmravacU3Pti1UXoI4PVY8e+PjRYbs7TXn1se0ZbrpySqB1OttvnEQ82mgEQa5Qt h94Nbax12wftPe9TCAfthwjbQY2I7vqC9G21lEc4YcJ7/As461CWhn3NQgAnjTLmL09m tN9SAEZZWI9bouraZ1ayaxMfgALQ9YC3y4otSjrn8JvlmF2R6uoXgQ1v3L7Wc0lujAMe ODGAXZUjCZH9EaUe/IDjSsU25MQ7jy/bfJJTVZjWP0dr55f7UPxFhFBM+KglV3OKk7iv LsiLPdg3BO+SbC+sId4ajXZ23MCkT4YFkInJTETeRyCh4BicO5RjoyGIPwJ4afQqiFUO z+wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736527413; x=1737132213; 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=24Dc1ozbi/clwrekfep1mnhCPerumrP3eLe3i+hSGqk=; b=knPlIWs7yw5HVYOpf2J1mj0y7AS78wM0zJNixJtE90qW9L1Y4f+FnMhr49Afwo9P17 PGUHvgw5BCJddT7Dh8BCBq2kER7x4clr6Q37dPYqrz1xmEsej3zUyseQS77HgSHizo4w jMf6J/m3XIZqfU12MhQjf0+FLgpUi/pJwM3uPZibyWKcnfQtMSmvgdMQpZmLTUmMM1lV J5O2GH75+d7H2NW7ewx66Sw5iAZNir6v+JUzu6OWBSKQ/OCyVy/ZpBquOPfxwZ/8RUe+ 3bNGBUAhNPvRjdfkbkYrdxoziyuxh6r033LUnELUUUtQXY/doMPtg1kIlSPkbvmBHeit 65ZQ== X-Forwarded-Encrypted: i=1; AJvYcCWSgbdrM7E5NDkF3g858Z7TGmdfzBZtaklsqeFR6HqLjTxwzg5BQ063O/cI+XXJC3Ft/rMKUqoCiHZvejs=@vger.kernel.org X-Gm-Message-State: AOJu0YyyyxhS89bIzRrx5VR+fZh97KjRMW8ndzF3x0On47VF0ZxBwdSg gHZp92bx4xrgRg33XAUmJeqohUD8wKpUHVdLOveMtCKXWYTtYbq9ZOF79obclQ== X-Gm-Gg: ASbGncu9XgqEmWSMoieBiwy271eeoF2rSCyL7gUR9fV8ke5dYkCwrQWeOqIuWgLUp0v eKpY9EOALctwhiPJGdJgxXPZyn1DIjanAuhbJndV0hRoXspVYNiEUHtJqkAvCq18Gjk1UyHiKGH mQLKmjjTAZXyhcX5mKCkgyh3M3579WRTbb9wqEbncjeejp12MqEvFwAD3gIBOevg60EyJE8LFBK fyBXBlvBDXy0N2fDsA59WjWylQuxRUlhttf5tdFx75I1XzhHxqy0Blf1g== X-Google-Smtp-Source: AGHT+IHihq/Gi/uNcUYMifWkuOm4gAuAgRcdTc97mmsMPs5byjq2HisMrtAUpvjr8MVUgetlzQtkSA== X-Received: by 2002:a17:902:f789:b0:20c:f3cf:50e9 with SMTP id d9443c01a7336-21aa07eb8b1mr2661345ad.4.1736527412672; Fri, 10 Jan 2025 08:43:32 -0800 (PST) Received: from google.com ([2620:15c:2d:3:99d3:ef93:6e2e:8b59]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d406a7536sm1723689b3a.161.2025.01.10.08.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 08:43:32 -0800 (PST) Date: Fri, 10 Jan 2025 08:43:28 -0800 From: Isaac Manjarres To: Lorenzo Stoakes Cc: Andrew Morton , kaleshsingh@google.com, jstultz@google.com, aliceryhl@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] mm/memfd: Use strncpy_from_user() to read memfd name Message-ID: References: <20250109185908.1006310-1-isaacmanjarres@google.com> <20250109185908.1006310-3-isaacmanjarres@google.com> <38fbe522-f757-4de9-acf3-1483b90898f6@lucifer.local> 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: <38fbe522-f757-4de9-acf3-1483b90898f6@lucifer.local> On Fri, Jan 10, 2025 at 12:48:44PM +0000, Lorenzo Stoakes wrote: > On Thu, Jan 09, 2025 at 10:59:05AM -0800, Isaac J. Manjarres wrote: > > The existing logic uses strnlen_user() to calculate the length of the > > memfd name from userspace and then copies the string into a buffer using > > copy_from_user(). This is error-prone, as the string length > > could have changed between the time when it was calculated and when the > > string was copied. The existing logic handles this by ensuring that the > > last byte in the buffer is the terminating zero. > > > > This handling is contrived and can better be handled by using > > strncpy_from_user(), which gets the length of the string and copies > > it in one shot. Therefore, simplify the logic for copying the memfd > > name by using strncpy_from_user(). > > > > No functional change. > > > > Reviewed-by: Alice Ryhl > > Signed-off-by: Isaac J. Manjarres > > LGTM, > > Reviewed-by: Lorenzo Stoakes > Thank you! --Isaac