From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 8DEBF201264 for ; Wed, 8 Jan 2025 18:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736361800; cv=none; b=gaGzHKJDz3bskvhrEYOokBwCz/wbrapbHFWMe+6zCnVoS70l9qTxO83M8mkvFCBTOMjJ0fyEsZnOS634X/FRwzdI0P1DFbfzUmH4y8rg8UVQSW/RMkRiPRtQotuk166cubQyMnIzTxsM9a6SVFZs7ke+lc96BK3SLsL0drzMNJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736361800; c=relaxed/simple; bh=sRlGwrOUES+1AvwHMRKvKwMn6d5L3g+jFxPdyKboE7Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CAnLu299MiHCD6zOy+6yn+1Snp7H7Xifz4palRNKhbAZk1XngjQiRQzP/doWEqmafw0JR3isohbZ2/Sw07swgOqUt4sikAeH6dCOjnwPXvQkKPM2DT82cwn1S0y+goMWgbkV6TCl1LLVW2SY0/SfIwUymqDltrscJLl25ezpjCY= 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=SS0+ltI0; arc=none smtp.client-ip=209.85.214.173 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="SS0+ltI0" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2163affd184so10965ad.1 for ; Wed, 08 Jan 2025 10:43:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736361797; x=1736966597; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=kXyCyPBOES+MEmnZ1MIuXOR61pDXzNXOigqF+2AH1Jw=; b=SS0+ltI04YMi5OdZPeQghL9Sxy8l2lg2smWkefslkywxTbBzB3qAPJ3rk4q1LHpgDn 1r2ou4eg1tCLMVz4p673XzBgxdj24yC24mBTC/JLfSeazpnjbyY8+MOnWmjzzqd+oLJR 5Gb1qo3vItPXIMa8EjVabEXyKzKpjoUSEtlUrP3TUPKBCvgyn7iKX9pVwbh0FCAoVIFV OJ6DGOAoLOXj7e4nYls1LtdZ+G7wHTiBoOpSVTeWtFUMkJKrrj111LymQoc2zZp/u+BZ v7I2CIE1yuQP3RobDvuF/b+rqLP7943LlqlN8uRRfvtF7i0s5VP2J6n/IefHYMPgHSKD 8SSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736361797; x=1736966597; h=in-reply-to:content-transfer-encoding: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=kXyCyPBOES+MEmnZ1MIuXOR61pDXzNXOigqF+2AH1Jw=; b=TxS2DO6fU3xLHYeHlWS7gaumGrJnDDw8m5+WQ7lLkNrKmnUN5Y0jPbmEdp6dFbv5Q4 a0Y8YuYOxO60FFjUL4PBok65WQxfb3Mtouq0Ru/Htxy2nk7NxcXwNw26B7SXr9WLqOsV HVQk7yQmEcdj7b5Z9Ppe0XvXlphuIDDRX/Wb26xfmB3ETA1sBrCS+dEa4d1wYvZfxZgD wb23MljXlSOJuqEoZYSP2QnegvoKu4PKS/rkQxAU+v1FQQduHSCZDr7oikY72YOIWTlW XJsB89d2whu0Hsxnr7/LMKuQ/wSEt+LFCVefoGL+5YgmDs926jJy92oLxAqkdGMVrWXB aYPw== X-Forwarded-Encrypted: i=1; AJvYcCWNrmii2sQKDFG2MC4IMRPvaWO4vPhRuVoXNUh/cmxhCCoJZUfDBJw8x4zHk/WtL0+AbYVmkv/IVar7ZI0=@vger.kernel.org X-Gm-Message-State: AOJu0YxvagobCHjjG6BcwOeOiHn/E8Obp/LJVw3pqKjoc5hlfwo2FQFk GQOaUoXEXZBFPjJHytn2dsMGOTHXXWy23tdZWb0ze6vznTKZGmPVThJwElFzOQ== X-Gm-Gg: ASbGncudVeBBIOHJhfd6d6LLgzFXtGjab4i1NJP+bqSnThrbC39DIEACa43IwH9mbFd bR223llhQpTL/qyw4ZbIyDYwh+WmNxQ9NwzQ57aaqHa4FUc+vj3qmjjBDQJyB5B6WSKpehsRcLO Gsn7aAmBiqvhysQNgmbeemYKw2nO6VNsoeciZmxfG/PA5wY/3enFJY7mUkAxqUtCaIhEuPSySj5 Z7YOqAASMSIpb1ipgG+Okf50kmp181SZe3bterAymAjWzTpwlJO5bK8ag== X-Google-Smtp-Source: AGHT+IEzodxXuJv8Ky7a9cVJO1HV7Z61fTYQPMZodCgj22Ovyfsljxhw+73JLpdWNJ1yEqEhRiwjMg== X-Received: by 2002:a17:903:2487:b0:215:8723:42d1 with SMTP id d9443c01a7336-21a8ed27aaamr18255ad.10.1736361796721; Wed, 08 Jan 2025 10:43:16 -0800 (PST) Received: from google.com ([2620:15c:2d:3:e514:4b22:2740:5ec1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad815842sm35624060b3a.7.2025.01.08.10.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 10:43:16 -0800 (PST) Date: Wed, 8 Jan 2025 10:43:12 -0800 From: Isaac Manjarres To: Alice Ryhl Cc: lorenzo.stoakes@oracle.com, Andrew Morton , kaleshsingh@google.com, jstultz@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] mm/memfd: Use strncpy_from_user() to read memfd name Message-ID: References: <20250107184804.4074147-1-isaacmanjarres@google.com> <20250107184804.4074147-3-isaacmanjarres@google.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jan 08, 2025 at 02:43:12PM +0100, Alice Ryhl wrote: > On Tue, Jan 7, 2025 at 7:48 PM 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. > > > > Signed-off-by: Isaac J. Manjarres > > Looks okay to me. One nit below, but: > > Reviewed-by: Alice Ryhl > > > + /* length does not include terminating zero */ > > + len = strncpy_from_user(name + MFD_NAME_PREFIX_LEN, uname, MFD_NAME_MAX_LEN + 1); > > Can we have this comment say "returned length" instead of just > "length"? Or just remove the comment. Initially I thought you were > talking about the last argument, and I was confused as that does > include the nul-terminator. > > Alice Yes, I will update it to say returned length and add your "Reviewed-by" tag. Thanks for this! --Isaac