Skip to content

Commit d3734b0

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== The following patchset contains fixes for recently applied Netfilter/IPVS updates to the net-next tree, most relevantly they are: * Fix sparse warnings introduced in the RCU conversion, from Julian Anastasov. * Fix wrong endianness in the size field of IPVS sync messages, from Simon Horman. * Fix missing if checking in nf_xfrm_me_harder, from Dan Carpenter. * Fix off by one access in the IPVS SCTP tracking code, again from Dan Carpenter. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 204cd4f + e7e6f63 commit d3734b0

File tree

11 files changed

+64
-55
lines changed

11 files changed

+64
-55
lines changed

include/net/ip_vs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,22 +678,22 @@ struct ip_vs_service_user_kern {
678678
u16af;
679679
u16protocol;
680680
union nf_inet_addraddr;/* virtual ip address */
681-
u16port;
681+
__be16port;
682682
u32fwmark;/* firwall mark of service */
683683

684684
/* virtual service options */
685685
char*sched_name;
686686
char*pe_name;
687687
unsigned intflags;/* virtual service flags */
688688
unsigned inttimeout;/* persistent timeout in sec */
689-
u32netmask;/* persistent netmask */
689+
__be32netmask;/* persistent netmask or plen */
690690
};
691691

692692

693693
struct ip_vs_dest_user_kern {
694694
/* destination server address */
695695
union nf_inet_addraddr;
696-
u16port;
696+
__be16port;
697697

698698
/* real server options */
699699
unsigned intconn_flags;/* connection flags */
@@ -721,7 +721,7 @@ struct ip_vs_service {
721721
__u32 fwmark; /* firewall mark of the service */
722722
unsigned intflags; /* service status flags */
723723
unsigned inttimeout; /* persistent timeout in ticks */
724-
__be32netmask; /* grouping granularity */
724+
__be32netmask; /* grouping granularity, mask/plen */
725725
struct net*net;
726726

727727
struct list_headdestinations; /* real server d-linked list */

include/uapi/linux/ip_vs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ struct ip_vs_daemon_user {
280280
#define IPVS_GENL_VERSION0x1
281281

282282
struct ip_vs_flags {
283-
__be32 flags;
284-
__be32 mask;
283+
__u32 flags;
284+
__u32 mask;
285285
};
286286

287287
/* Generic Netlink command attributes */

net/netfilter/ipvs/ip_vs_conn.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
966966
struct ip_vs_iter_state *iter = seq->private;
967967

968968
for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
969-
rcu_read_lock();
970969
hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
971970
/* __ip_vs_conn_get() is not needed by
972971
* ip_vs_conn_seq_show and ip_vs_conn_sync_seq_show
@@ -977,16 +976,19 @@ static void *ip_vs_conn_array(struct seq_file *seq, loff_t pos)
977976
}
978977
}
979978
rcu_read_unlock();
979+
rcu_read_lock();
980980
}
981981

982982
return NULL;
983983
}
984984

985985
static void *ip_vs_conn_seq_start(struct seq_file *seq, loff_t *pos)
986+
__acquires(RCU)
986987
{
987988
struct ip_vs_iter_state *iter = seq->private;
988989

989990
iter->l = NULL;
991+
rcu_read_lock();
990992
return *pos ? ip_vs_conn_array(seq, *pos - 1) :SEQ_START_TOKEN;
991993
}
992994

@@ -1006,28 +1008,24 @@ static void *ip_vs_conn_seq_next(struct seq_file *seq, void *v, loff_t *pos)
10061008
e = rcu_dereference(hlist_next_rcu(&cp->c_list));
10071009
if (e)
10081010
return hlist_entry(e, struct ip_vs_conn, c_list);
1009-
rcu_read_unlock();
10101011

10111012
idx = l - ip_vs_conn_tab;
10121013
while (++idx < ip_vs_conn_tab_size) {
1013-
rcu_read_lock();
10141014
hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
10151015
iter->l = &ip_vs_conn_tab[idx];
10161016
return cp;
10171017
}
10181018
rcu_read_unlock();
1019+
rcu_read_lock();
10191020
}
10201021
iter->l = NULL;
10211022
return NULL;
10221023
}
10231024

10241025
static void ip_vs_conn_seq_stop(struct seq_file *seq, void *v)
1026+
__releases(RCU)
10251027
{
1026-
struct ip_vs_iter_state *iter = seq->private;
1027-
struct hlist_head *l = iter->l;
1028-
1029-
if (l)
1030-
rcu_read_unlock();
1028+
rcu_read_unlock();
10311029
}
10321030

10331031
static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
235235
/* Mask saddr with the netmask to adjust template granularity */
236236
#ifdef CONFIG_IP_VS_IPV6
237237
if (svc->af == AF_INET6)
238-
ipv6_addr_prefix(&snet.in6, &iph->saddr.in6, svc->netmask);
238+
ipv6_addr_prefix(&snet.in6, &iph->saddr.in6,
239+
(__force __u32) svc->netmask);
239240
else
240241
#endif
241242
snet.ip = iph->saddr.ip & svc->netmask;
@@ -583,9 +584,9 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
583584
#ifdef CONFIG_IP_VS_IPV6
584585
if (svc->af == AF_INET6) {
585586
if (!skb->dev) {
586-
struct net *net = dev_net(skb_dst(skb)->dev);
587+
struct net *net_ = dev_net(skb_dst(skb)->dev);
587588

588-
skb->dev = net->loopback_dev;
589+
skb->dev = net_->loopback_dev;
589590
}
590591
icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
591592
} else

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,9 +1164,13 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,
11641164
}
11651165

11661166
#ifdef CONFIG_IP_VS_IPV6
1167-
if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
1168-
ret = -EINVAL;
1169-
goto out_err;
1167+
if (u->af == AF_INET6) {
1168+
__u32 plen = (__force __u32) u->netmask;
1169+
1170+
if (plen < 1 || plen > 128) {
1171+
ret = -EINVAL;
1172+
goto out_err;
1173+
}
11701174
}
11711175
#endif
11721176

@@ -1277,9 +1281,13 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
12771281
}
12781282

12791283
#ifdef CONFIG_IP_VS_IPV6
1280-
if (u->af == AF_INET6 && (u->netmask < 1 || u->netmask > 128)) {
1281-
ret = -EINVAL;
1282-
goto out;
1284+
if (u->af == AF_INET6) {
1285+
__u32 plen = (__force __u32) u->netmask;
1286+
1287+
if (plen < 1 || plen > 128) {
1288+
ret = -EINVAL;
1289+
goto out;
1290+
}
12831291
}
12841292
#endif
12851293

@@ -1460,8 +1468,11 @@ void ip_vs_service_net_cleanup(struct net *net)
14601468
static inline void
14611469
ip_vs_forget_dev(struct ip_vs_dest *dest, struct net_device *dev)
14621470
{
1471+
struct ip_vs_dest_dst *dest_dst;
1472+
14631473
spin_lock_bh(&dest->dst_lock);
1464-
if (dest->dest_dst && dest->dest_dst->dst_cache->dev == dev) {
1474+
dest_dst = rcu_dereference_protected(dest->dest_dst, 1);
1475+
if (dest_dst && dest_dst->dst_cache->dev == dev) {
14651476
IP_VS_DBG_BUF(3, "Reset dev:%s dest %s:%u ,dest->refcnt=%d\n",
14661477
dev->name,
14671478
IP_VS_DBG_ADDR(dest->af, &dest->addr),
@@ -1934,8 +1945,8 @@ static struct ip_vs_service *ip_vs_info_array(struct seq_file *seq, loff_t pos)
19341945
}
19351946

19361947
static void *ip_vs_info_seq_start(struct seq_file *seq, loff_t *pos)
1948+
__acquires(RCU)
19371949
{
1938-
19391950
rcu_read_lock();
19401951
return *pos ? ip_vs_info_array(seq, *pos - 1) : SEQ_START_TOKEN;
19411952
}
@@ -1990,6 +2001,7 @@ static void *ip_vs_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
19902001
}
19912002

19922003
static void ip_vs_info_seq_stop(struct seq_file *seq, void *v)
2004+
__releases(RCU)
19932005
{
19942006
rcu_read_unlock();
19952007
}
@@ -2134,7 +2146,7 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v)
21342146
{
21352147
struct net *net = seq_file_single_net(seq);
21362148
struct ip_vs_stats *tot_stats = &net_ipvs(net)->tot_stats;
2137-
struct ip_vs_cpu_stats *cpustats = tot_stats->cpustats;
2149+
struct ip_vs_cpu_stats __percpu *cpustats = tot_stats->cpustats;
21382150
struct ip_vs_stats_user rates;
21392151
int i;
21402152

@@ -2871,6 +2883,7 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
28712883
struct ip_vs_service *svc)
28722884
{
28732885
struct ip_vs_scheduler *sched;
2886+
struct ip_vs_pe *pe;
28742887
struct nlattr *nl_service;
28752888
struct ip_vs_flags flags = { .flags = svc->flags,
28762889
.mask = ~0 };
@@ -2887,17 +2900,17 @@ static int ip_vs_genl_fill_service(struct sk_buff *skb,
28872900
} else {
28882901
if (nla_put_u16(skb, IPVS_SVC_ATTR_PROTOCOL, svc->protocol) ||
28892902
nla_put(skb, IPVS_SVC_ATTR_ADDR, sizeof(svc->addr), &svc->addr) ||
2890-
nla_put_u16(skb, IPVS_SVC_ATTR_PORT, svc->port))
2903+
nla_put_be16(skb, IPVS_SVC_ATTR_PORT, svc->port))
28912904
goto nla_put_failure;
28922905
}
28932906

28942907
sched = rcu_dereference_protected(svc->scheduler, 1);
2908+
pe = rcu_dereference_protected(svc->pe, 1);
28952909
if (nla_put_string(skb, IPVS_SVC_ATTR_SCHED_NAME, sched->name) ||
2896-
(svc->pe &&
2897-
nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, svc->pe->name)) ||
2910+
(pe && nla_put_string(skb, IPVS_SVC_ATTR_PE_NAME, pe->name)) ||
28982911
nla_put(skb, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags) ||
28992912
nla_put_u32(skb, IPVS_SVC_ATTR_TIMEOUT, svc->timeout / HZ) ||
2900-
nla_put_u32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
2913+
nla_put_be32(skb, IPVS_SVC_ATTR_NETMASK, svc->netmask))
29012914
goto nla_put_failure;
29022915
if (ip_vs_genl_fill_stats(skb, IPVS_SVC_ATTR_STATS, &svc->stats))
29032916
goto nla_put_failure;
@@ -3010,7 +3023,7 @@ static int ip_vs_genl_parse_service(struct net *net,
30103023
} else {
30113024
usvc->protocol = nla_get_u16(nla_protocol);
30123025
nla_memcpy(&usvc->addr, nla_addr, sizeof(usvc->addr));
3013-
usvc->port = nla_get_u16(nla_port);
3026+
usvc->port = nla_get_be16(nla_port);
30143027
usvc->fwmark = 0;
30153028
}
30163029

@@ -3050,7 +3063,7 @@ static int ip_vs_genl_parse_service(struct net *net,
30503063
usvc->sched_name = nla_data(nla_sched);
30513064
usvc->pe_name = nla_pe ? nla_data(nla_pe) : NULL;
30523065
usvc->timeout = nla_get_u32(nla_timeout);
3053-
usvc->netmask = nla_get_u32(nla_netmask);
3066+
usvc->netmask = nla_get_be32(nla_netmask);
30543067
}
30553068

30563069
return 0;
@@ -3076,7 +3089,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
30763089
return -EMSGSIZE;
30773090

30783091
if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
3079-
nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
3092+
nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
30803093
nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
30813094
(atomic_read(&dest->conn_flags) &
30823095
IP_VS_CONN_F_FWD_MASK)) ||
@@ -3185,7 +3198,7 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
31853198
memset(udest, 0, sizeof(*udest));
31863199

31873200
nla_memcpy(&udest->addr, nla_addr, sizeof(udest->addr));
3188-
udest->port = nla_get_u16(nla_port);
3201+
udest->port = nla_get_be16(nla_port);
31893202

31903203
/* If a full entry was requested, check for the additional fields */
31913204
if (full_entry) {
@@ -3210,8 +3223,8 @@ static int ip_vs_genl_parse_dest(struct ip_vs_dest_user_kern *udest,
32103223
return 0;
32113224
}
32123225

3213-
static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
3214-
const char *mcast_ifn, __be32 syncid)
3226+
static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __u32 state,
3227+
const char *mcast_ifn, __u32 syncid)
32153228
{
32163229
struct nlattr *nl_daemon;
32173230

@@ -3232,8 +3245,8 @@ static int ip_vs_genl_fill_daemon(struct sk_buff *skb, __be32 state,
32323245
return -EMSGSIZE;
32333246
}
32343247

3235-
static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state,
3236-
const char *mcast_ifn, __be32 syncid,
3248+
static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __u32 state,
3249+
const char *mcast_ifn, __u32 syncid,
32373250
struct netlink_callback *cb)
32383251
{
32393252
void *hdr;

net/netfilter/ipvs/ip_vs_lblc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct ip_vs_lblc_entry {
104104
*/
105105
struct ip_vs_lblc_table {
106106
struct rcu_headrcu_head;
107-
struct hlist_head __rcu bucket[IP_VS_LBLC_TAB_SIZE]; /* hash bucket */
107+
struct hlist_headbucket[IP_VS_LBLC_TAB_SIZE]; /* hash bucket */
108108
struct timer_list periodic_timer; /* collect stale entries */
109109
atomic_t entries; /* number of entries */
110110
int max_size; /* maximum size of entries */

net/netfilter/ipvs/ip_vs_lblcr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct ip_vs_lblcr_entry {
284284
*/
285285
struct ip_vs_lblcr_table {
286286
struct rcu_headrcu_head;
287-
struct hlist_head __rcu bucket[IP_VS_LBLCR_TAB_SIZE]; /* hash bucket */
287+
struct hlist_headbucket[IP_VS_LBLCR_TAB_SIZE]; /* hash bucket */
288288
atomic_t entries; /* number of entries */
289289
int max_size; /* maximum size of entries */
290290
struct timer_list periodic_timer; /* collect stale entries */

net/netfilter/ipvs/ip_vs_pe_sip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static const char *ip_vs_dbg_callid(char *buf, size_t buf_len,
1313
const char *callid, size_t callid_len,
1414
int *idx)
1515
{
16-
size_t len = min(min(callid_len, (size_t)64), buf_len - *idx - 1);
16+
size_t max_len = 64;
17+
size_t len = min3(max_len, callid_len, buf_len - *idx - 1);
1718
memcpy(buf + *idx, callid, len);
1819
buf[*idx+len] = '\0';
1920
*idx += len + 1;

net/netfilter/ipvs/ip_vs_proto_sctp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ enum ipvs_sctp_event_t {
208208
IP_VS_SCTP_EVE_LAST
209209
};
210210

211-
static enum ipvs_sctp_event_t sctp_events[255] = {
211+
static enum ipvs_sctp_event_t sctp_events[256] = {
212212
IP_VS_SCTP_EVE_DATA_CLI,
213213
IP_VS_SCTP_EVE_INIT_CLI,
214214
IP_VS_SCTP_EVE_INIT_ACK_CLI,

0 commit comments

Comments
 (0)