fs/ceph/crypto.c:281:9: sparse: sparse: non size-preserving integer to pointer cast
kernel test robot
build bottree: https://github.com/ceph/ceph-client.git testing head: 3f007b9f327745c94aec312a28973b28f6a51fc4 commit: 88d679bc66688124f73a2e30617c12a14bb5aeff [35/47] ceph: convert remaining helper paths to BLOG logging config: x86_64-randconfig-2300-20261031 (https://download.01.org/0day-ci/archive/20261031/[email protected]/config) compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1) sparse: v0.6.5-rc1-21-g84ec0658 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261031/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> fs/ceph/crypto.c:281:9: sparse: sparse: non size-preserving integer to pointer cast
fs/ceph/crypto.c:498:9: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:498:9: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:509:9: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:509:9: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:610:17: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:610:17: sparse: sparse: non size-preserving integer to pointer cast fs/ceph/crypto.c:619:9: sparse: sparse: non size-preserving integer to pointer cast
vim +281 fs/ceph/crypto.c
214
215 int ceph_encode_encrypted_dname(struct inode *parent, char *buf, int elen)
216 {
217 struct ceph_client *cl = ceph_inode_to_client(parent);
218 struct inode *dir = parent;
219 char *p = buf;
220 u32 len;
221 int prefix_len = 0;
222 int name_len = elen;
223 int ret;
224 u8 *cryptbuf = NULL;
225
226 /* Handle the special case of snapshot names that start with '_' */
227 if (ceph_snap(dir) == CEPH_SNAPDIR && *p == '_') {
228 dir = parse_longname(parent, p, &name_len);
229 if (IS_ERR(dir))
230 return PTR_ERR(dir);
231 p++; /* skip initial '_' */
232 prefix_len = 1;
233 }
234
235 if (!fscrypt_has_encryption_key(dir))
236 goto out;
237
238 /*
239 * Convert cleartext d_name to ciphertext. If result is longer than
240 * CEPH_NOHASH_NAME_MAX, sha256 the remaining bytes
241 *
242 * See: fscrypt_setup_filename
243 */
244 if (!fscrypt_fname_encrypted_size(dir, name_len, NAME_MAX, &len)) {
245 elen = -ENAMETOOLONG;
246 goto out;
247 }
248
249 /* Allocate a buffer appropriate to hold the result */
250 cryptbuf = kmalloc(len > CEPH_NOHASH_NAME_MAX ? NAME_MAX : len,
251 GFP_KERNEL);
252 if (!cryptbuf) {
253 elen = -ENOMEM;
254 goto out;
255 }
256
257 ret = fscrypt_fname_encrypt(dir,
258 &(struct qstr)QSTR_INIT(p, name_len),
259 cryptbuf, len);
260 if (ret) {
261 elen = ret;
262 goto out;
263 }
264
265 /* hash the end if the name is long enough */
266 if (len > CEPH_NOHASH_NAME_MAX) {
267 u8 hash[SHA256_DIGEST_SIZE];
268 u8 *extra = cryptbuf + CEPH_NOHASH_NAME_MAX;
269
270 /*
271 * hash the extra bytes and overwrite crypttext beyond that
272 * point with it
273 */
274 sha256(extra, len - CEPH_NOHASH_NAME_MAX, hash);
275 memcpy(extra, hash, SHA256_DIGEST_SIZE);
276 len = CEPH_NOHASH_NAME_MAX + SHA256_DIGEST_SIZE;
277 }
278
279 /* base64 encode the encrypted name */
280 elen = base64_encode(cryptbuf, len, p, false, BASE64_IMAP);
> 281 boutc_bounded(cl, "base64-encoded ciphertext name = %.*s\n",
282 (elen, BLOG_STR(p, elen)), (elen, (const char *)p));
283
284 /* To understand the 240 limit, see CEPH_NOHASH_NAME_MAX comments */
285 WARN_ON(elen > 240);
286 if (elen > 240) {
287 elen = -ENAMETOOLONG;
288 goto out;
289 }
290
291 if (dir != parent) {
292 int total_len;
293 /* leading '_' is already there; append _<inum> */
294 char suffix[CEPH_ENCRYPTED_SNAP_INO_SUFFIX_MAX];
295
296 ret = snprintf(suffix, sizeof(suffix), "_%llu", dir->i_ino);
297 total_len = prefix_len + elen + ret;
298 if (total_len > NAME_MAX) {
299 elen = -ENAMETOOLONG;
300 goto out;
301 }
302
303 memcpy(p + elen, suffix, ret);
304 /* Include the leading '_' skipped by p. */
305 elen = total_len;
306 }
307
308 out:
309 kfree(cryptbuf);
310 if (dir != parent) {
311 if ((inode_state_read_once(dir) & I_NEW))
312 discard_new_inode(dir);
313 else
314 iput(dir);
315 }
316 return elen;
317 }
318
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki