mbox series

[v4,0/3] Fix inefficiences and rename nla_strlcpy

Message ID 20201030153647.4408-1-laniel_francis@privacyrequired.com
Headers show
Series Fix inefficiences and rename nla_strlcpy | expand

Message

Francis Laniel Oct. 30, 2020, 3:36 p.m. UTC
From: Francis Laniel <laniel_francis@privacyrequired.com>

Hi.


I hope your relatives and yourselves are fine.

This patch set answers to first three issues listed in:
https://github.com/KSPP/linux/issues/110

To sum up, the first patch fixes an inefficiency where some bytes in dst were
written twice, one with 0 the other with src content.
The second one modifies nla_strlcpy to return the same value as strscpy,
i.e. number of bytes written or -E2BIG if src was truncated.
The third rename nla_strlcpy to nla_strscpy.

Unfortunately, I did not find how to create struct nlattr objects so I tested
my modifications on simple char* and withing GDB with tc to get to
tcf_proto_check_kind.
This is why I tagged this patch set as RFC.

If you see any way to improve the code or have any remark, feel free to comment.


Best regards and take care of yourselves.

Francis Laniel (3):
  Fix unefficient call to memset before memcpu in nla_strlcpy.
  Modify return value of nla_strlcpy to match that of strscpy.
  treewide: rename nla_strlcpy to nla_strscpy.

 drivers/infiniband/core/nldev.c            | 10 +++---
 drivers/net/can/vxcan.c                    |  4 +--
 drivers/net/veth.c                         |  4 +--
 include/linux/genl_magic_struct.h          |  2 +-
 include/net/netlink.h                      |  4 +--
 include/net/pkt_cls.h                      |  2 +-
 kernel/taskstats.c                         |  2 +-
 lib/nlattr.c                               | 42 ++++++++++++++--------
 net/core/fib_rules.c                       |  4 +--
 net/core/rtnetlink.c                       | 12 +++----
 net/decnet/dn_dev.c                        |  2 +-
 net/ieee802154/nl-mac.c                    |  2 +-
 net/ipv4/devinet.c                         |  2 +-
 net/ipv4/fib_semantics.c                   |  2 +-
 net/ipv4/metrics.c                         |  2 +-
 net/netfilter/ipset/ip_set_hash_netiface.c |  4 +--
 net/netfilter/nf_tables_api.c              |  6 ++--
 net/netfilter/nfnetlink_acct.c             |  2 +-
 net/netfilter/nfnetlink_cthelper.c         |  4 +--
 net/netfilter/nft_ct.c                     |  2 +-
 net/netfilter/nft_log.c                    |  2 +-
 net/netlabel/netlabel_mgmt.c               |  2 +-
 net/nfc/netlink.c                          |  2 +-
 net/sched/act_api.c                        |  2 +-
 net/sched/act_ipt.c                        |  2 +-
 net/sched/act_simple.c                     |  4 +--
 net/sched/cls_api.c                        |  2 +-
 net/sched/sch_api.c                        |  2 +-
 net/tipc/netlink_compat.c                  |  2 +-
 29 files changed, 73 insertions(+), 61 deletions(-)

Comments

Kees Cook Oct. 30, 2020, 7:25 p.m. UTC | #1
On Fri, Oct 30, 2020 at 04:36:46PM +0100, laniel_francis@privacyrequired.com wrote:
> diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c

> index 2a76a2f5ed88..f9b053b30a7b 100644

> --- a/net/sched/sch_api.c

> +++ b/net/sched/sch_api.c

> @@ -1170,7 +1170,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev,

>  #ifdef CONFIG_MODULES

>  	if (ops == NULL && kind != NULL) {

>  		char name[IFNAMSIZ];

> -		if (nla_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {

> +		if (nla_strlcpy(name, kind, IFNAMSIZ) > 0) {

>  			/* We dropped the RTNL semaphore in order to

>  			 * perform the module load.  So, even if we

>  			 * succeeded in loading the module we have to


Oops, I think this should be >= 0 ?

-- 
Kees Cook
Francis Laniel Nov. 13, 2020, 9:38 a.m. UTC | #2
Le vendredi 30 octobre 2020, 20:25:38 CET Kees Cook a écrit :
> On Fri, Oct 30, 2020 at 04:36:46PM +0100, laniel_francis@privacyrequired.com 

wrote:
> > diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c

> > index 2a76a2f5ed88..f9b053b30a7b 100644

> > --- a/net/sched/sch_api.c

> > +++ b/net/sched/sch_api.c

> > @@ -1170,7 +1170,7 @@ static struct Qdisc *qdisc_create(struct net_device

> > *dev,> 

> >  #ifdef CONFIG_MODULES

> >  

> >  	if (ops == NULL && kind != NULL) {

> >  	

> >  		char name[IFNAMSIZ];

> > 

> > -		if (nla_strlcpy(name, kind, IFNAMSIZ) < IFNAMSIZ) {

> > +		if (nla_strlcpy(name, kind, IFNAMSIZ) > 0) {

> > 

> >  			/* We dropped the RTNL semaphore in order to

> >  			

> >  			 * perform the module load.  So, even if we

> >  			 * succeeded in loading the module we have to

> 

> Oops, I think this should be >= 0 ?


Good catch! I will modify this, rebase my patch on top of master, test it a 
bit more than what I did for the v4 and push  v5!