Skip to content

Commit b4391db

Browse files
arndbdavem330
authored andcommitted
netlink: fix nla_put_{u8,u16,u32} for KASAN
When CONFIG_KASAN is enabled, the "--param asan-stack=1" causes rather large stack frames in some functions. This goes unnoticed normally because CONFIG_FRAME_WARN is disabled with CONFIG_KASAN by default as of commit 3f181b4 ("lib/Kconfig.debug: disable -Wframe-larger-than warnings with KASAN=y"). The kernelci.org build bot however has the warning enabled and that led me to investigate it a little further, as every build produces these warnings: net/wireless/nl80211.c:4389:1: warning: the frame size of 2240 bytes is larger than 2048 bytes [-Wframe-larger-than=] net/wireless/nl80211.c:1895:1: warning: the frame size of 3776 bytes is larger than 2048 bytes [-Wframe-larger-than=] net/wireless/nl80211.c:1410:1: warning: the frame size of 2208 bytes is larger than 2048 bytes [-Wframe-larger-than=] net/bridge/br_netlink.c:1282:1: warning: the frame size of 2544 bytes is larger than 2048 bytes [-Wframe-larger-than=] Most of this problem is now solved in gcc-8, which can consolidate the stack slots for the inline function arguments. On older compilers we can add a workaround by declaring a local variable in each function to pass the inline function argument. Cc: stable@vger.kernel.org Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6098d7d commit b4391db

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

include/net/netlink.h

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,10 @@ static inline int nla_parse_nested(struct nlattr *tb[], int maxtype,
773773
*/
774774
static inline int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value)
775775
{
776-
return nla_put(skb, attrtype, sizeof(u8), &value);
776+
/* temporary variables to work around GCC PR81715 with asan-stack=1 */
777+
u8 tmp = value;
778+
779+
return nla_put(skb, attrtype, sizeof(u8), &tmp);
777780
}
778781

779782
/**
@@ -784,7 +787,9 @@ static inline int nla_put_u8(struct sk_buff *skb, int attrtype, u8 value)
784787
*/
785788
static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value)
786789
{
787-
return nla_put(skb, attrtype, sizeof(u16), &value);
790+
u16 tmp = value;
791+
792+
return nla_put(skb, attrtype, sizeof(u16), &tmp);
788793
}
789794

790795
/**
@@ -795,7 +800,9 @@ static inline int nla_put_u16(struct sk_buff *skb, int attrtype, u16 value)
795800
*/
796801
static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value)
797802
{
798-
return nla_put(skb, attrtype, sizeof(__be16), &value);
803+
__be16 tmp = value;
804+
805+
return nla_put(skb, attrtype, sizeof(__be16), &tmp);
799806
}
800807

801808
/**
@@ -806,7 +813,9 @@ static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value)
806813
*/
807814
static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value)
808815
{
809-
return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, value);
816+
__be16 tmp = value;
817+
818+
return nla_put_be16(skb, attrtype | NLA_F_NET_BYTEORDER, tmp);
810819
}
811820

812821
/**
@@ -817,7 +826,9 @@ static inline int nla_put_net16(struct sk_buff *skb, int attrtype, __be16 value)
817826
*/
818827
static inline int nla_put_le16(struct sk_buff *skb, int attrtype, __le16 value)
819828
{
820-
return nla_put(skb, attrtype, sizeof(__le16), &value);
829+
__le16 tmp = value;
830+
831+
return nla_put(skb, attrtype, sizeof(__le16), &tmp);
821832
}
822833

823834
/**
@@ -828,7 +839,9 @@ static inline int nla_put_le16(struct sk_buff *skb, int attrtype, __le16 value)
828839
*/
829840
static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value)
830841
{
831-
return nla_put(skb, attrtype, sizeof(u32), &value);
842+
u32 tmp = value;
843+
844+
return nla_put(skb, attrtype, sizeof(u32), &tmp);
832845
}
833846

834847
/**
@@ -839,7 +852,9 @@ static inline int nla_put_u32(struct sk_buff *skb, int attrtype, u32 value)
839852
*/
840853
static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value)
841854
{
842-
return nla_put(skb, attrtype, sizeof(__be32), &value);
855+
__be32 tmp = value;
856+
857+
return nla_put(skb, attrtype, sizeof(__be32), &tmp);
843858
}
844859

845860
/**
@@ -850,7 +865,9 @@ static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value)
850865
*/
851866
static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value)
852867
{
853-
return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, value);
868+
__be32 tmp = value;
869+
870+
return nla_put_be32(skb, attrtype | NLA_F_NET_BYTEORDER, tmp);
854871
}
855872

856873
/**
@@ -861,7 +878,9 @@ static inline int nla_put_net32(struct sk_buff *skb, int attrtype, __be32 value)
861878
*/
862879
static inline int nla_put_le32(struct sk_buff *skb, int attrtype, __le32 value)
863880
{
864-
return nla_put(skb, attrtype, sizeof(__le32), &value);
881+
__le32 tmp = value;
882+
883+
return nla_put(skb, attrtype, sizeof(__le32), &tmp);
865884
}
866885

867886
/**
@@ -874,7 +893,9 @@ static inline int nla_put_le32(struct sk_buff *skb, int attrtype, __le32 value)
874893
static inline int nla_put_u64_64bit(struct sk_buff *skb, int attrtype,
875894
u64 value, int padattr)
876895
{
877-
return nla_put_64bit(skb, attrtype, sizeof(u64), &value, padattr);
896+
u64 tmp = value;
897+
898+
return nla_put_64bit(skb, attrtype, sizeof(u64), &tmp, padattr);
878899
}
879900

880901
/**
@@ -887,7 +908,9 @@ static inline int nla_put_u64_64bit(struct sk_buff *skb, int attrtype,
887908
static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value,
888909
int padattr)
889910
{
890-
return nla_put_64bit(skb, attrtype, sizeof(__be64), &value, padattr);
911+
__be64 tmp = value;
912+
913+
return nla_put_64bit(skb, attrtype, sizeof(__be64), &tmp, padattr);
891914
}
892915

893916
/**
@@ -900,7 +923,9 @@ static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value,
900923
static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value,
901924
int padattr)
902925
{
903-
return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, value,
926+
__be64 tmp = value;
927+
928+
return nla_put_be64(skb, attrtype | NLA_F_NET_BYTEORDER, tmp,
904929
padattr);
905930
}
906931

@@ -914,7 +939,9 @@ static inline int nla_put_net64(struct sk_buff *skb, int attrtype, __be64 value,
914939
static inline int nla_put_le64(struct sk_buff *skb, int attrtype, __le64 value,
915940
int padattr)
916941
{
917-
return nla_put_64bit(skb, attrtype, sizeof(__le64), &value, padattr);
942+
__le64 tmp = value;
943+
944+
return nla_put_64bit(skb, attrtype, sizeof(__le64), &tmp, padattr);
918945
}
919946

920947
/**
@@ -925,7 +952,9 @@ static inline int nla_put_le64(struct sk_buff *skb, int attrtype, __le64 value,
925952
*/
926953
static inline int nla_put_s8(struct sk_buff *skb, int attrtype, s8 value)
927954
{
928-
return nla_put(skb, attrtype, sizeof(s8), &value);
955+
s8 tmp = value;
956+
957+
return nla_put(skb, attrtype, sizeof(s8), &tmp);
929958
}
930959

931960
/**
@@ -936,7 +965,9 @@ static inline int nla_put_s8(struct sk_buff *skb, int attrtype, s8 value)
936965
*/
937966
static inline int nla_put_s16(struct sk_buff *skb, int attrtype, s16 value)
938967
{
939-
return nla_put(skb, attrtype, sizeof(s16), &value);
968+
s16 tmp = value;
969+
970+
return nla_put(skb, attrtype, sizeof(s16), &tmp);
940971
}
941972

942973
/**
@@ -947,7 +978,9 @@ static inline int nla_put_s16(struct sk_buff *skb, int attrtype, s16 value)
947978
*/
948979
static inline int nla_put_s32(struct sk_buff *skb, int attrtype, s32 value)
949980
{
950-
return nla_put(skb, attrtype, sizeof(s32), &value);
981+
s32 tmp = value;
982+
983+
return nla_put(skb, attrtype, sizeof(s32), &tmp);
951984
}
952985

953986
/**
@@ -960,7 +993,9 @@ static inline int nla_put_s32(struct sk_buff *skb, int attrtype, s32 value)
960993
static inline int nla_put_s64(struct sk_buff *skb, int attrtype, s64 value,
961994
int padattr)
962995
{
963-
return nla_put_64bit(skb, attrtype, sizeof(s64), &value, padattr);
996+
s64 tmp = value;
997+
998+
return nla_put_64bit(skb, attrtype, sizeof(s64), &tmp, padattr);
964999
}
9651000

9661001
/**
@@ -1010,7 +1045,9 @@ static inline int nla_put_msecs(struct sk_buff *skb, int attrtype,
10101045
static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
10111046
__be32 addr)
10121047
{
1013-
return nla_put_be32(skb, attrtype, addr);
1048+
__be32 tmp = addr;
1049+
1050+
return nla_put_be32(skb, attrtype, tmp);
10141051
}
10151052

10161053
/**

0 commit comments

Comments
 (0)