Skip to content

Commit 57f22c8

Browse files
committed
Merge tag 'strlcpy-removal-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull strlcpy removal from Kees Cook: "As promised, this is 'part 2' of the hardening tree, late in -rc1 now that all the other trees with strlcpy() removals have landed. One new user appeared (in bcachefs) but was a trivial refactor. The kernel is now free of the strlcpy() API! - Remove of the final (very recent) user of strlcpy() (in bcachefs) - Remove the strlcpy() API. Long live strscpy()" * tag 'strlcpy-removal-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: string: Remove strlcpy() bcachefs: Replace strlcpy() with strscpy()
2 parents 18b5cb6 + d262700 commit 57f22c8

File tree

7 files changed

+3
-82
lines changed

7 files changed

+3
-82
lines changed

fs/bcachefs/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,8 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
13861386
prt_bdevname(&name, ca->disk_sb.bdev);
13871387

13881388
if (c->sb.nr_devices == 1)
1389-
strlcpy(c->name, name.buf, sizeof(c->name));
1390-
strlcpy(ca->name, name.buf, sizeof(ca->name));
1389+
strscpy(c->name, name.buf, sizeof(c->name));
1390+
strscpy(ca->name, name.buf, sizeof(ca->name));
13911391

13921392
printbuf_exit(&name);
13931393

include/linux/fortify-string.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -214,51 +214,6 @@ __kernel_size_t __fortify_strlen(const char * const POS p)
214214
return ret;
215215
}
216216

217-
/* Defined after fortified strlen() to reuse it. */
218-
extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
219-
/**
220-
* strlcpy - Copy a string into another string buffer
221-
*
222-
* @p: pointer to destination of copy
223-
* @q: pointer to NUL-terminated source string to copy
224-
* @size: maximum number of bytes to write at @p
225-
*
226-
* If strlen(@q) >= @size, the copy of @q will be truncated at
227-
* @size - 1 bytes. @p will always be NUL-terminated.
228-
*
229-
* Do not use this function. While FORTIFY_SOURCE tries to avoid
230-
* over-reads when calculating strlen(@q), it is still possible.
231-
* Prefer strscpy(), though note its different return values for
232-
* detecting truncation.
233-
*
234-
* Returns total number of bytes written to @p, including terminating NUL.
235-
*
236-
*/
237-
__FORTIFY_INLINE size_t strlcpy(char * const POS p, const char * const POS q, size_t size)
238-
{
239-
const size_t p_size = __member_size(p);
240-
const size_t q_size = __member_size(q);
241-
size_t q_len; /* Full count of source string length. */
242-
size_t len; /* Count of characters going into destination. */
243-
244-
if (p_size == SIZE_MAX && q_size == SIZE_MAX)
245-
return __real_strlcpy(p, q, size);
246-
q_len = strlen(q);
247-
len = (q_len >= size) ? size - 1 : q_len;
248-
if (__builtin_constant_p(size) && __builtin_constant_p(q_len) && size) {
249-
/* Write size is always larger than destination. */
250-
if (len >= p_size)
251-
__write_overflow();
252-
}
253-
if (size) {
254-
if (len >= p_size)
255-
fortify_panic(__func__);
256-
__underlying_memcpy(p, q, len);
257-
p[len] = '\0';
258-
}
259-
return q_len;
260-
}
261-
262217
/* Defined after fortified strnlen() to reuse it. */
263218
extern ssize_t __real_strscpy(char *, const char *, size_t) __RENAME(strscpy);
264219
/**
@@ -272,12 +227,6 @@ extern ssize_t __real_strscpy(char *, const char *, size_t) __RENAME(strscpy);
272227
* @p buffer. The behavior is undefined if the string buffers overlap. The
273228
* destination @p buffer is always NUL terminated, unless it's zero-sized.
274229
*
275-
* Preferred to strlcpy() since the API doesn't require reading memory
276-
* from the source @q string beyond the specified @size bytes, and since
277-
* the return value is easier to error-check than strlcpy()'s.
278-
* In addition, the implementation is robust to the string changing out
279-
* from underneath it, unlike the current strlcpy() implementation.
280-
*
281230
* Preferred to strncpy() since it always returns a valid string, and
282231
* doesn't unnecessarily force the tail of the destination buffer to be
283232
* zero padded. If padding is desired please use strscpy_pad().

include/linux/string.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ extern char * strcpy(char *,const char *);
6666
#ifndef __HAVE_ARCH_STRNCPY
6767
extern char * strncpy(char *,const char *, __kernel_size_t);
6868
#endif
69-
#ifndef __HAVE_ARCH_STRLCPY
70-
size_t strlcpy(char *, const char *, size_t);
71-
#endif
7269
#ifndef __HAVE_ARCH_STRSCPY
7370
ssize_t strscpy(char *, const char *, size_t);
7471
#endif

lib/nlattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ EXPORT_SYMBOL(nla_find);
758758
* @dstsize: Size of destination buffer.
759759
*
760760
* Copies at most dstsize - 1 bytes into the destination buffer.
761-
* Unlike strlcpy the destination buffer is always padded out.
761+
* Unlike strscpy() the destination buffer is always padded out.
762762
*
763763
* Return:
764764
* * srclen - Returns @nla length (not including the trailing %NUL).

lib/string.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,6 @@ char *strncpy(char *dest, const char *src, size_t count)
103103
EXPORT_SYMBOL(strncpy);
104104
#endif
105105

106-
#ifndef __HAVE_ARCH_STRLCPY
107-
size_t strlcpy(char *dest, const char *src, size_t size)
108-
{
109-
size_t ret = strlen(src);
110-
111-
if (size) {
112-
size_t len = (ret >= size) ? size - 1 : ret;
113-
__builtin_memcpy(dest, src, len);
114-
dest[len] = '\0';
115-
}
116-
return ret;
117-
}
118-
EXPORT_SYMBOL(strlcpy);
119-
#endif
120-
121106
#ifndef __HAVE_ARCH_STRSCPY
122107
ssize_t strscpy(char *dest, const char *src, size_t count)
123108
{

lib/test_fortify/write_overflow-strlcpy-src.c

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/test_fortify/write_overflow-strlcpy.c

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)