From patchwork Fri Nov 15 11:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdul Rahim X-Patchwork-Id: 13876124 Received: from sonic310-19.consmr.mail.sg3.yahoo.com (sonic310-19.consmr.mail.sg3.yahoo.com [106.10.244.139]) (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 2380A7D3F4 for ; Fri, 15 Nov 2024 11:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=106.10.244.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731669885; cv=none; b=ImgDw6TvNePTeBMYNvjDuAhfxfHZzD/vuL2pJ3TZT8sQxl1WHSnKiSOgB9GqE/6ZvJaBkKwqtQl1cw3ZTWHhttz4q8YFNelBrr4JhCdns7ie4a8C8m+VTb3b5aLuGS2OIpQZL3PR5CaJmToVHNwh8/eFFIcNe8eo1S6qB01AKh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731669885; c=relaxed/simple; bh=t0Fl5hfSyZNiuPBvDejZLRu40BusxN7bDAG45nb+WZg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:References; b=L4PgYlosbs2k3VpebWEzMF/HJGDN+jzZj26z04ehV529ZB432BQjvy9Sm9xs0FIBLh8bYrEtKU42sAzFME/QkyZiunb+8Rhdhz4NUKKKFWqXEOaD7C/0QEQQqHQBWT+r7Qjh8kG19S+k8KvfaotquPVhfz9prGyt5awFED01DbY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=myyahoo.com; spf=pass smtp.mailfrom=myyahoo.com; dkim=pass (2048-bit key) header.d=myyahoo.com header.i=@myyahoo.com header.b=UBzKEsqC; arc=none smtp.client-ip=106.10.244.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=myyahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=myyahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=myyahoo.com header.i=@myyahoo.com header.b="UBzKEsqC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=myyahoo.com; s=s2048; t=1731669875; bh=slYMq2Zmby0491A1PE7H8ao60Az9AMutaRCL53H62hw=; h=From:To:Cc:Subject:Date:References:From:Subject:Reply-To; b=UBzKEsqC6jRZgIPLCoQVeFPWXtHsgRSieURYcZ5Ap8oWLFpHXoiiFg1k+ufRAVqTVIRaz49LRLRLiXPqahoLgpo9PqYl1eJVRkVBS2rcTuvlXIOFR7jhX6y7Jk9VggnW8K2x6wHDVCvNQYDMNqBi4gseCBIOQ1uLG/5IdYS98ODQbshproUyxq7yM0mR5XVIkj9wPc+WzP7T6qKIH7W0YKz+Wtgjho8WL2ElE+SRjmE4NTa7pzcp6h5f/Dyx7SKBl+Y/HF7xuKJ99EWhZr2n90PvSWYpgvwcFKZOBRvmTsqNu5luKUEoZMhDY6mTJDYvKSoxenfUsJxn7OOX47Widw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1731669875; bh=zNitpFp8uUxC1vF8jUB/vl1kv8bRHd2Yq1qQ3KoSzwO=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=nh03Wytec4Rp9xXsV5r0Alh40FTZhZp0/YBxUYFvVktvXC8DaURlwd3DGTj79o06fIRz7U4XM0nRaunxLfariFar+60nVBI5Tr+YaxTaYnaUJWx4YgUENeYbFkeaMGph/aFl2M8VVqzmSmXeeipVnNXRtv8N9QJYDq4XXYHffx6ubCjWghOC+ia9tZoU/IhSt8s54YMpuJO9iuzt2+o+VTp9stOLf+JRcidULG6BTukH7qUtpYtjug+WcBaPqug51OUlJbhVwbTPWfMQj5T7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p8jogHwUsH1lDfB4xzpFrcFGghVNIHmvvBrMBy1k_Olyoj 5UaulKe377KFuxw54_RqOlNyjXHSnh72cqumhI735rbvmF9qwxxNBuS1j306T7kEAuo9i.3lb1xH Y1V3lfKs2dGad4eOQ3ueNMMrE4GygJWcEIA8D5L43k07KrO1U6.hSuEqkopI5WcWCHGitKCb00Ak .vQ60DEx4kXx0U74s_KTL.tdvv47l4YHdK60HP9N6rRUU4O5qt_eZxw-- X-Sonic-MF: X-Sonic-ID: 87d31a78-8c80-4d80-bee8-a391d60809c3 Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.sg3.yahoo.com with HTTP; Fri, 15 Nov 2024 11:24:35 +0000 Received: by hermes--production-sg3-5b7954b588-2czcw (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 30b2b63ae3584f58ae1ae168a243895b; Fri, 15 Nov 2024 11:24:33 +0000 (UTC) From: Abdul Rahim To: xiubli@redhat.com, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Abdul Rahim Subject: [PATCH v2] ceph: Use strscpy() instead of strcpy() Date: Fri, 15 Nov 2024 16:54:19 +0530 Message-ID: <20241115112419.11137-1-abdul.rahim@myyahoo.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241115112419.11137-1-abdul.rahim.ref@myyahoo.com> strcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. [1] this fixes checkpatch warning: WARNING: Prefer strscpy over strcpy [1] : https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy Signed-off-by: Abdul Rahim --- Changes since v1: - Added third parameter in strscpy() - Added comment to explain where the limit `NAME_MAX+1` is comming from as suggested by Christophe JAILLET Link to v1: https://lore.kernel.org/lkml/20241111221037.92853-1-abdul.rahim@myyahoo.com/ The function __get_snap_name() is assigned to .get_name() from struct export_operations, when `ceph_snap(inode) != CEPH_NOSNAP`. `struct export_operations` is comming from `include/linux/exportfs.h`, and according to [1], the operation get_name assumes that the variable `name` is pointing to a buffer of size NAME_MAX+1 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/exportfs.h?h=v6.12-rc7#n203 fs/ceph/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ceph/export.c b/fs/ceph/export.c index 44451749c544..96421f2b6cec 100644 --- a/fs/ceph/export.c +++ b/fs/ceph/export.c @@ -452,7 +452,11 @@ static int __get_snap_name(struct dentry *parent, char *name, goto out; if (ceph_snap(inode) == CEPH_SNAPDIR) { if (ceph_snap(dir) == CEPH_NOSNAP) { - strcpy(name, fsc->mount_options->snapdir_name); + /* .get_name() from struct export_operations assumes + * that its 'name' parameter is pointing to a + * NAME_MAX+1 sized buffer */ + strscpy(name, fsc->mount_options->snapdir_name, + NAME_MAX+1); err = 0; } goto out;