From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [PATCHv2 net-next 02/15] lib: nlattr: set extack msg if validate_nla fails Date: Thu, 14 Dec 2017 12:45:58 -0700 Message-ID: <93b097a5-f0d8-156b-cbd8-af49700dcde8@gmail.com> References: <20171214183905.23066-1-aring@mojatatu.com> <20171214183905.23066-3-aring@mojatatu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, netdev@vger.kernel.org, kernel@mojatatu.com To: Alexander Aring , jhs@mojatatu.com Return-path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:42842 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbdLNTqB (ORCPT ); Thu, 14 Dec 2017 14:46:01 -0500 Received: by mail-pg0-f65.google.com with SMTP id e14so4096170pgr.9 for ; Thu, 14 Dec 2017 11:46:00 -0800 (PST) In-Reply-To: <20171214183905.23066-3-aring@mojatatu.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 12/14/17 11:38 AM, Alexander Aring wrote: > This patch sets a generic netlink error message if the validation of the > netlink attribute failed. It avoids several different settings of > netlink messages by handle nla_parse_nested on error case. > > Suggested-by: David Ahern > Signed-off-by: Alexander Aring > --- > lib/nlattr.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/lib/nlattr.c b/lib/nlattr.c > index dfa55c873c13..a2a9506b2fb7 100644 > --- a/lib/nlattr.c > +++ b/lib/nlattr.c > @@ -253,8 +253,10 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, > if (policy) { > err = validate_nla(nla, maxtype, policy); > if (err < 0) { > - if (extack) > + if (extack) { > + NL_SET_ERR_MSG(extack, "Failed to validate netlink attribute"); > extack->bad_attr = nla; > + } > goto errout; > } > } > I have a similar patch: if (policy) { err = validate_nla(nla, maxtype, policy); if (err < 0) { - if (extack) - extack->bad_attr = nla; + NL_SET_ERR_MSG_ATTR(extack, nla, + "Attribute failed policy validation"); goto errout; } } Wording wise it notes policy validation failed but more importantly it combines setting the error message and bad_attr into 1 macro.